Mysql format for image

Codes here !

Moderators: macek, egami, gesf

User avatar
wmdrumaizi
New php-forum User
New php-forum User
Posts: 40
Joined: Thu Jan 23, 2003 5:15 pm
Location: Malaysia
Contact:

Mysql format for image

Postby wmdrumaizi » Thu Apr 10, 2003 5:24 pm

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.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Apr 10, 2003 10:36 pm

MySQl fieald type - BLOB

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Mon Apr 14, 2003 11:51 pm

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?

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Apr 15, 2003 1:25 am

Code: Select all

<?
  $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'];
?>

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Wed Apr 16, 2003 2:03 am

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.


Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Thu Apr 17, 2003 4:24 am

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.

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Thu Apr 17, 2003 11:22 am

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.

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Thu Apr 17, 2003 3:53 pm

<? 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.

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Thu Apr 17, 2003 9:37 pm

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.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Mon Apr 21, 2003 1:06 am

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.

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Mon Apr 21, 2003 3:21 pm

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.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

cron