Reputation: 35
trying to uploadimage in database with this
$file = $_FILES['image']['tmp_name'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size == false)
{
echo "Not an image";
}
else
{
mysqli_query($link, "INSERT into Events (imagetype, Attachments)
VALUES ('$image_name', '$image')");
}
connection.php includes my connection
trying to retrieve image with this:
include "connection.php";
$query = "SELECT imagetype,Attachments from Events where E_id='$id' ";
$result = mysqli_query($link,$query);
while ($row = mysqli_fetch_assoc($result))
{
header("Content-type:image/jpeg");
echo mysqli_result($row['Attachments'], 0);
}
Upvotes: 1
Views: 90
Reputation: 1416
Here is your error.
In your code, echo mysqli_result($row['Attachments'], 0);
in this line, I am not clear why do you use mysqli_result
.
If your datatype for Attachments
is VARCHAR
, I think $row['Attachments']
is enough.
So your code for showing image should be
while($row= mysqli_fetch_assoc($result)){
header("Content-type:image/jpeg");
echo ($row['Attachments']);
Upvotes: 1