Mysql format for image

A

Anonymous

Guest
Hi guys,
I've created mysql table to store visitor data e.g name, company, e-mail, picture,..etc..

My question is what is mysql table format to store image(.jpeg, .bmp, .gif). In MS Access I used OLE....

Any help would be appreciated.
 
How do you call on the image to display it as image. Im assuming the image is stored as binary or hex, so how do i display it on a page?
 
Code:
<?
  $res=mysql_query("SELECT `img` FROM `imgtable` WHERE `imgid` = '$_GET[img]'") or die (mysql_error());

$data=mysql_fetch_array($res);


  header("Content-type: image/gif");
  echo $data['img'];
?>
 
sorry to say, but that displayed this error...

Warning: Cannot modify header information - headers already sent by (output started at c:\imagetest.php:10) in c:\imagetest.php on line 19

and then the echo turned out as characters.
 
OFFTOPIC!
http://www.php-forum.com/p/viewtopic.php?t=1714&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=1684&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=1533&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=1256&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=1193&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=1068&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=482&highlight=headers+already+sent

http://www.php-forum.com/p/viewtopic.php?t=414&highlight=headers+already+sent
 
now i just wonder? how can i make this useful so that i can display an image in the middle of a page. ill try it while i wait, in awe and amazement for thou master.
 
MySQL is a database. not a filesystem. it should be used for storing data not files. images are files. you should keep them on the filesystem.

note: just my opinion.
 
<? header("Content-type: image/gif");

$db = mysql_connect("localhost", "joel", "password");
mysql_select_db("rocknz",$db);

@$id = $_GET["id"];

$res=mysql_query("SELECT `image` FROM `newbands` WHERE id='$id'") or die (mysql_error());

$data=mysql_fetch_array($res);

echo $data['image'];
?>

I figured it out, i did i did. I have that above code in a image.php file, then i just have <img src="image.php"> and it loads the image which i stored in the database.
 
Now i dunno how to send an image to the database. I've just been using phpmyadmin, i know how to use a file field but i dont know how to get the contents from that.
 
I'm with Redcircle on this one - why store an image in the database?

every time you view an image you will have to instantiate a database connection, thus slowing it down for data retrieval scripts.

personally I cannot see one plausible reason for storing an image in a database that cannot be accomplished and surpassed by using filesystem storage or a combination of filesystem storage for the actual image and database storage for associated information.

Still, if you want to slow down your applications and seriously limit any extensibility of your scripts, I guess the choice is yours.

subnote: you could just about stream the binary data straight into an image tag...
echo '<img src="/-/data:image/jpeg;base64,' .$row['img']. '" />';
only works in a couple of browsers and the browser element size limit restricts it to 1KB (1024b), so is next to useless anyway.
 
Yeah, I can see what you mean, for sure. I shall work through the file upload stuff. I suppose there is a way to upload a file and then store the file name in mysql? of course there is.
 
Back
Top