i have upload the images in databases but when i want to display it the images cannot display..i don’t know why it cannot display..maybe have something wrong in my coding..can you please help me??
upload.php
<?php
$id = $_POST['account'];
$code = $_POST['code'];
$price = $_POST['price'];
echo $file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "Please select an image.";
else
{
$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 "That's not an image.";
else
{
if (!$insert = mysql_query("INSERT INTO menu
VALUES('$code','$price','$image','$id')"))
echo "Problem uploading images.";
else
{
$lastid = $code;
echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
}
}
}
?>
get.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("food", $con);
$id = addslashes($_REQUEST['FoodId']);
$image = mysql_query("SELECT * FROM menu WHERE FoodId=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
Please confirm by manually looking through your DB that the image has been stored successfully, and infact is readable?, post the contents of the stored image.
FYI, it is usually better to store the image in a folder on your server, rather than in the DB and just store the path to the image in the DB.
If you wanted to store path to image, something like this would work:
the folder is /uploadedimages/ and would need to be write enabled (chmod777)
Calling from another file;
You can call the image anytime from the DB with the query you used before;
Obviously the $id is something you have already defined on the php page.
EDIT: The edit made by someone else to me post was unnecessary – there is nothing wrong with using single quotes with variables and it clearly shows where you are adding variables in. If you wanted to show how to use double quotes you should give both options available and explain the difference. Your edit was tacky and badly written, adding a space after the double quote.