Re: Upload and Display images with Mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- Kpromos <info@xxxxxxxxxxx> wrote:
> Dears All,
> 
> I'm looking for a simple script that will permitme
> to upload images in a mysql database, calling out
> the images with a function from a mysql database
> (calling them from an id variable). I have just
> tried this tutorial
>
http://www.phpbuilder.com/columns/florian19991014.php3
> but it seems to me that there's nothing to do, as
> images aren't displayed even if all seems to
> function correctly. The doubt is that images are
> stored as bynary files System.Byte[], so it may be
> that I can use the simple <img
> src="view.php?id=$id">.
> I'm testing all in my Windows PC. Anybody can help
> me? 

I actually remember looking at that PHPBuilder.com
article a few years ago.  Unless you're in a situation
where you are required to store your graphic in the
database, it would be better to store the graphic in
the file system of your operating system, and then
merely capture the path to the file in a column of the
database.  So, for example, if you upload your a
picture called "myPhoto.jpg" to a path (assuming
you're on UNIX/Linux) called "/home/myDirectory", then
the full path to your picture would be:
"/home/myDirectory/photos/myPhoto.jpg" (without the
quotes, of course).

In the column of your database, INSERT the path to
your photo.  For example:

$sql = "INSERT into Table1
        (id, photo)
        VALUES (null,
'/home/myDirectory/photos/myPhoto.jpg')";

Later on, when you want to view your photo, you would
do a SELECT statement on the table to get the path to
your photo and then echo it out to the browser.  For
example, if the "id" of your photo was "1":

$query = "SELECT Table1.photo
          WHERE Table1.id = '1'";

$result = mysql_query($query, $connection_info_here)
    or die("Couldn't pull photo.");

while ($row = mysql_fetch_array($result))
{
    $photo = $row['photo'];
}

To display the photo, as you already know, just use
<img> tags and echo statement:

<img src="<?php echo $photo; ?>">

I have not included any error checking.  This is just
a skeleton way of doing it.

The PHP manual does a good job of explaining file
uploads which you'll be required to do for uploads
regardless of where you store the graphic (either in
the file system or in the database).

http://us4.php.net/features.file-upload


=====
~Rachel


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux