Page 1 of 1

trying to insert image into database

Posted: Tue Jan 22, 2008 1:32 pm
by sk121506
i can upload an image and insert the information i want about it into a database, the problem is, im trying to insert the image itself into the database as a medium blob. im not sure what im doing wrong because when i echo the query and try selecting the image to view it after it has been inserted into the database, a bunch of funny looking symbols appear. is this the binary form of the image? how can i get around this? some of my code is below

$content = addslashes(fread(fopen($file,"r"), filesize($filetmpName)));
$query = "INSERT INTO $Images (Image_Name, Size, Image, Username, Type, URL) VALUES ('$filename', '$filesize', '$content', '$_SESSION[username]', '$filetype', '$URL')";
$result= MYSQL_QUERY($query);
echo $query;


$query = "SELECT Image, Type FROM $Images WHERE ImageId='11'";
$result= MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0, "Image");
<img src="http://www.xxxxxxx.com/imageAd.php?file=11">

Re: trying to insert image into database

Posted: Tue Jan 22, 2008 3:23 pm
by Kieran Huggins
This is a very common design folly (a mistake we've all made) - the general consensus is to store the file in the filesystem and the meta in the DB. A search should locate a more detailed strategy for you.