elk dolk wrote:
Hi all,
I am new to web programming.
I have code to add pictures to a MYSQL database. Now I can't seem to figure out how to get them back out ! so we can see them.
The MySQL doesn't seem to be a problem (yet), also I'm trying to learn PHP.
What I usually do is to load the images in a folder "img" and then the name of the pic (i.e. "myphoto.jpg") in the database, so i retrieve the name of the pic with:
Code: <?php
$connex = MySQL_connect(server,login,password);
$sql_query = "select picname from photos where...";
$result = MySQL_query($sql_query,$connex);
$row = MySQL_fetch_array($result);
?>
and then:
Code: echo "<img src=".$row['photoFileName']." alt='photo'>";
but I can't see the photo
Any pointers or code samples will be greatly appreciated...
Are you storing the whole file in the database or just the path to the file?
If you're storing just the path, then your script is pointing to the
wrong directory and/or the file it's trying to reference doesn't exist
(or a permissions issue maybe).
If you're storing the whole file you need a new php script to pull it
back out.
Then in your html code you do:
echo '<img src="/path/to/display_image.php?image_id=' . $row['imageid']
. '">';
That will hit 'display_image.php' and pull the image contents out of the
database.
See
http://www.phpriot.com/d/articles/database/images-in-mysql/page8.html
for an example.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php