Page 1 of 1

How to display a .jpg or .gif file?

Posted: Thu Jun 15, 2006 9:20 am
by sharky
I'm going to display a .jpg or .gif file from my db. What I did --> In my db ::

FIELD = photos --> 'images.jpg'
TYPE = VARCHAR
LENGTH/VALUES = 20


I stored my .jpg files in my localhost under same path as my phpmyadmin. This is what I did ::

Code: Select all

<tr>
              <td width="104" height="101" align="center"><img src="<?php echo $row['photos']; ?>" width="51"                   
                 height="88">
              </td>
              <td width="10" valign="">
              </td>
</tr>
how do I store/display the images properly? Thanks

Posted: Thu Jun 15, 2006 9:26 am
by bdlang

Posted: Thu Jun 15, 2006 10:06 am
by pickle
You've pretty much got it. Probably what's happening is your path to the image is wrong. Try:

Code: Select all

<img src = "/phpmyadmin/<?php echo $row['photos']; ?>" .... />
Make sure you've got the full path to the image.

Posted: Thu Jun 15, 2006 10:58 am
by sharky
Oh. The 'images.jpg' is stored in the same path as phpmyadmin, which is the localhost. So, there's no path (I think). I could just type ::

Code: Select all

<img src="<?php echo $row['photos']; ?>" width="51" height="88">
No? Or maybe the easiest way is to declare the path with a variable? How can I do that?

Posted: Thu Jun 15, 2006 11:07 am
by pickle
So the images are stored right at the root? The full url of an image would be:

Code: Select all

http://www.yourdomain.com/someimage.jpg
???

If so, just put a slash in front of the image name to make the tag look like:

Code: Select all

<img src = "/<?PHP echo $row['photos']; />" ... />

Posted: Thu Jun 15, 2006 11:34 am
by sharky
Yes, my image is stored in ::

Code: Select all

http://mydomain.someImage.jpg
I didn't put the slash. Then I added the slash. It looks like ::

Code: Select all

<img src="/<?php echo $row['photos']; ?>/" width="51" height="88">
I also tried ::

Code: Select all

<img src="/<?php echo $row['photos']; ?>" width="51" height="88"/>
Does not seem to work. Not sure if the slashes are at the right place.

In my phpmyadmin :: should I use VARCHAR or the BLOB for the type? Right now I'm using VARCHAR(20).

Posted: Thu Jun 15, 2006 11:41 am
by pickle
Whoa! Are you storing the image data in the database as well? By image data I mean are you reading in the JPG and storing the actual pixel-by-pixel information in the DB? If so, ~bdlang was correct. Do a Google search about storing images in a database. One of your search results should have everything you need to know.

Don't use a varchar - it's not nearly big enough. Use a blob (for small images) or mediumblob (for medium sized images).

Posted: Thu Jun 15, 2006 1:47 pm
by bdlang
Hmm. I definitely thought based on the initial post (edited?) that the images were stored in the database. Maybe it was too early for PHP questions.... :) Only problem is, I'm still confused, and that can't be good. :?

Posted: Thu Jun 15, 2006 4:00 pm
by sharky
Well. I did store something in the database.

FIELD :: photo
TYPE :: mediumBLOB
VALUE :: (I browsed .jpg from my localhost, same path as my phpmyadmin) myImage.jpeg


When TYPE is mediumBLOB, it displays garbage in my showProduct.php file. When TYPE is tinyBLOB, it displays a broken .jpg file. My php ::

Code: Select all

<img src="\<?php echo $row['photos']; ?>" width="51" height="88">

Anything else I should add? Or my slash should be somewhere else.

Posted: Fri Jun 16, 2006 9:37 am
by pickle
Did you do a Google search? You can't just echo that data, you have to use a PHP file to dump the jpg headers & then the image data - essentially mimicing a JPG file.