I need urgent help! For two days I've been trying to find the source code to upload image to database and display, after trying
all the codes I kept getting all sorts of errors.
I'm using phpmyadmin.
1) Upload & Display image of any size < 5mb
2) upload & provide click-able link for PDF size file < 10mb
3) restrict up to only 3 latest posts on a page
It works by inserting the picture into database but doesn't allow me to upload more than 500kb which results in partial or no display.
upload.php
[code]
upload.php
<?php
include "_database.php";
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = mysqli_real_escape_string($conn,$data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO picture (picture1) VALUES ('$data')";
$results = mysqli_query($conn,$query) or die("fail connect");
// Print results
print "Thank you, your file has been uploaded.";
echo "<a href='action.php'>main</a>";
}
else {
print "No image selected/uploaded";
}
// Close our MySQL Link
?>
<?php
#to display picture code
//php echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['picture1'] ).'"/>'; dont forget to add the open php and close
?>
action.php
This is for display, apparently, picture cannot be properly uploaded because of file size.
<?php include "_database.php"; ?>
<html>
<head><title></title></head>
<style>
table tr td { border:1px solid black; }
#size { display:block;
}
</style>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="2048000000" type="hidden">
<input name='image' type="file">
<input value="Submit" type="submit">
<table >
<tr>
<td>ID</td>
<td>picture</td>
<td>display</td>
</tr>
<tr>
<?php
$link1 = "SELECT * FROM picture";
$result = $conn->query($link1) or die ("fucking");
if($result->num_rows>0){
while($row = $result->fetch_assoc()){
?>
<td><?php echo $row["ID"];?></td>
<td><div id="size"><?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['picture1'] ).'"width="200px" height="500px"/>'; ?></div></td>
<td><a href="display.php?id=<?php echo $row["ID"];?>">display</a></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>