Re: Output graphic or other download file to client's browser

From: Date: Sat, 21 Apr 2001 21:05:34 +0000
Subject: Re: Output graphic or other download file to client's browser
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49702@lists.php.net to get a copy of this message
Hi It is possible though quite complicated. You must write some kind of a "proxy" with PHP. The process looks something like this: The php script checks if the user is ok, reads the image file and then echoes it out to the client. - simple as it may sound. But there is a couple of points. Point #1. Since PHP is HTML embeded langauge, the default mime type of it's output is "text/html". So you will need to form the head of the http responce manually. This would look something like this: header("Content-Type: ".$mime_type); header("Content-Length: ".$image_size_in_bytes); $mime_type="image/pjpeg"; -this would be for JPG's $mime_type="image/gif"; -this would be for GIF's (not sure though) anyway, each file type "has" it's own mime_type - it's for you to determine which has which. then you may do: echo $binary_data_read_from_image_file; Point #2. How to preserve the original name of the image file. The problem is that the name of requested resource (or file name in this case) cannot be changed. In other words, if you try to save the image, that was downloaded via URL "retrieve_image.php?file=someimage.jpg&user=jack&pass=kcaj", the cleint (web browser) would sugest to save it as "retrieve_image.php" and not as "someimage.jpg". I might be wrong but the only way to trick the client is this: echo "<img src=\"path/retrieve_image.php\\someimage.jpg?file=someimage.jpg&user=jack&pa ss=kcaj\">"; this way the client thinks it's requesting "someimage.jpg", but the server is serving "retrieve_image.php" ;) I hope this will help you P.S. this all has worked for me, when i needed to serve the mail attachments from webmail

« previous php.general (#49702) next »