View Full Version : load images from database to website
i have loaded my images into the database thanks for your help but am having problems loading them to be viewed on the website can anyone help please especially with the code example.
hello,
I will assume that you are familiar with getting Text strings from a Database.
The procedure for an image is extremely similar. Most important is setting the Mime Type for the file, this means the very first thing sent should be
header('content-type: image/jpeg');
or image/gif or image/png if you need.
Perform your normal DB check to get the row with the image that you want, and then use something similar to
echo $row["image_field_name"];
Here is my complete code to display an image
header('content-type: image/jpeg');
$key = @$HTTP_GET_VARS["key"];
if (empty($key)) {
$key = @$HTTP_POST_VARS["key"];
}
if (empty($key)) {
die();
}
$conn = mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);
$tkey = "" . $key . "";
$strsql = "SELECT * FROM `images` WHERE `image_id` = " . $tkey;
$rs = mysql_query($strsql, $conn) or die(mysql_error());
if (!($row = mysql_fetch_array($rs))) {
die("File not exists.");
}
echo $row["image_large"];
mysql_free_result($rs);
mysql_close($conn);
well maybe i dont understand when you say mime types my database is mysql and there is nothing their for mime types i tried using your code but my page is still blank
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.