I am storing images into a database that are being uploaded by users using this form.
profiletest.php
<form action="profiletest.php" method="POST" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="image"/>
<input type="submit" name="submit" value="Submit"/>
</form>
Here is the code that stores the images into the database
<?php
if (isset($_POST['submit']))
{
if (getimagesize($_FILES['image']['tmp_name'])== FALSE)
{
echo "Please select an image.";
}
else
{
$name= addslashes($_FILES['image']['name']);
$image= base64_encode(file_get_contents(addslashes($_FILES['image']['tmp_name'])));
saveimage($name,$image);
}
}
function saveimage($name, $image)
{
$conn = mysqli_connect("localhost","root","","loginsystem");
$sql="insert into testimage(name,image) values('$name', '$image')";
$query=mysqli_query($conn,$sql);
if ($query)
{
echo "<br/>Image Uploaded.";
}
else
{
echo "<br/>Image not uploaded";
}
}
?>
I then display those images in the exploretest.php page
exploretest.php
<?php
display();
function display(){
$conn = mysqli_connect("localhost","root","","loginsystem");
$sql="select * from testimage";
$query=mysqli_query($conn, $sql);
$num=mysqli_num_rows($query);
for ($i=0; $i < $num; $i++) {
$result=mysqli_fetch_array($query);
$img=$result['image'];
echo '<img class="exploreimg" src="data:image;base64, '.$img.'" style="max-height:300px;max-width:300px; margin-left:50px; margin-right:50px; padding-bottom:20px; padding-top:30px;">';
echo '<a href="' . $img . '" src="data:image;base64, '.$img.'" "download="imageName"><img src="img/downloadbutton.png" alt="Download" style="max-height:50px; max-width: 100px; float: center; line-height: 10;"/></a>';
}
}
?>
I use this piece of code to generate a download button for the user to download the chosen image
echo '<a href="' . $img . '" src="data:image;base64, '.$img.'" "download="imageName"><img src="img/downloadbutton.png" alt="Download" style="max-height:50px; max-width: 100px; float: center; line-height: 10;"/></a>';
Everytime I press one of the download buttons the error 414 displays.
I am storing the images in my database using Longblob
Does anyone know why this is happening.