Pulling jpeg name images out of MySQL onto PHP page

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am new to PHP and MySql.  What I would like to do is have my PHP page
pull the name of an image (jpeg, bmp, etc.) out of MySQL and display
image from another directory.  I don't want the actual image saved in
the DB, just the name.

I have the connection established from the Web Page to MySql, all I
want is how to display the image part.  Does anyone have any
straightforward code to show me how to do this?  Is there a better way
that is not too complicated?  Remember, I am a newbie.


Re: Pulling jpeg name images out of MySQL onto PHP page

MS contained the following:

Quoted text here. Click to load it

Assuming you are storing image names and alt text, this should work

$path="/images/";  // absolute path to images directory
$sql="SELECT imagefield, alt_text FROM imagetable";
echo "<img src='$path".$myrow['imagefield']."'

Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Re: Pulling jpeg name images out of MySQL onto PHP page

MS wrote:
Quoted text here. Click to load it

Straightforward?  Boy, am not sure if you want to display this image
inline or as an image src...

For inline, you need to open the image file:

$Image = imagecreatefromjpeg($ImageName.jpg)

.... do stuff with the image here if you wish...

header("content-type: image/jpeg")

Image already exists as a .jpg on disk NOT in a database, create a link
to it.

$Query = "select DirFilePath from FileDatabase where
$db = $chk->query($Query);
....db error glue stuff here.
$info = $chk->fetchrow();

for ease of use, combine your DirFilePath with ImageName.jpg
  ( /usr/local/images/imagename.jpg ) or something like that.
<img src="/usr/local/images/imagename.jpg">
.... more html/php code here.

your results may vary!

Site Timeline