Forum Moderators: coopster

Message Too Old, No Replies

PHP, Blob and picture

PHP, Blob and picture

         

unknown

8:02 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



I have a blob field in my mysql DB, I store a picture in it but I have no idea how to display my picture from my DB.

senior mcinvale

8:06 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



create a PHP script with the document type of your image format (ie gif, jpg or png) that pulls the data out of the database.

jatar_k

8:16 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld unknown

It is usually better not to store the actual image in the db. It is much better to store the path to the image in the db and have the image stored in a directory somewhere.

Shadi

8:21 pm on Jul 14, 2003 (gmt 0)

10+ Year Member





$sql = "SELECT Pic FROM Pictures WHERE ID=$id";
if(!($result=@mysql_query($sql))) showerror;

$data=@mysql_fetch_array($result);

if (!empty($data['Pic']))
{
//Change content type to your file type
header("Content-Type: image/gif");
print $data['Pic'] ;
}

i recommend that when placing the data into the database you actually take the datatype then, therefore you can output the info on the fly without having to manually set the content type each time.

lasko

8:07 am on Jul 15, 2003 (gmt 0)

10+ Year Member



Have to agree with Jatar_k

Put the absolute path of the image in a field and then use php to grab it.

If you build many web sites like I do, you will best have the image stored on one server and use one Mysql database to grab images and text etc.

I recently built a 500 page web site by importing all the data into a mysql. Works great and with virtually no errors, no broken links :)

Shadi

8:42 am on Jul 15, 2003 (gmt 0)

10+ Year Member



Yes i have to agree with both of you, i have never used themethod of storing these images in the database, usually just the location pointing to where the image is stored. But the method i posted above should do what you want should you insist on it ;)