[liphp] Code

Christopher R. Merlo [email protected]
Sun, 15 Jun 2003 23:12:27 -0400


Tim:
I'm hoping you remember this post.

On 2003-03-26 23:30 -0500, Tim Sailer <[email protected]> wrote:

> OK, here goes a fairly lengthy email with some code to show how
> to upload and display images to/from a MySql database.

[ ... ]

> Create the php file "photoupload.php":
> <?
>   $dbh=mysql_connect("localhost","user","pass") or die("Can not connect");
>   mysql_select_db ("dbname");
> 
>   #build the binary data element
>   $data = addslashes(fread(fopen($photo,"r"), filesize($photo))) or die (mysql_error());
>   #Note that there will also be $photo_size which will hold the size of the uploaded image
>   #which can/should be used to check for sanity (no 1G files, etc)
> 
>   $result=MYSQL_QUERY("insert into picture (0,\"$data\", photo_type=\"$photo_type\")") or die (mysql_error());
>   echo "File Uploaded";
> ?> 
> 
> If all works as planned, you should get the 'File Uploaded' message, and have
> another row added to your 'picture' table.

Using your ideas, I'm getting stuff into my DB.  Awesome.  A million
thanks.  (It's actually Excel files at the moment, but just about any
file type appears to work.
http://turing.matcmp.ncc.edu/accounts/reference.php is the link.  None
of you have accounts, but feel free to visit that page, and hit the
view source link at the bottom.)

Later in this email, you explained how to view the picture in the PHP
file.  But how would you provide a download link, and not show the
file on screen?

TIA,
-c

-- 
[email protected]        http://turing.matcmp.ncc.edu/~cmerlo

Some men are discovered; others are found out.