Re: File sending?
| From: | Richard Lynch | Date: | Tue, 27 Feb 2001 23:32:13 +0000 |
| Subject: | Re: File sending? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41912@lists.php.net to get a copy of this message | ||
>Is it possible to send a file to a browser?
>I would like to allow people to download a file, but I don't want to give
away the path to >the file, so a normal link wouldn't work.
>I am hoping there is a way to use php to send the file using code, rather
than trying to >first copy the file to a temp dir then give them the link,
then worry about deleting the temp >dir again.
<A
HREF=yoursite.com/download.php/whatever.doc?filename=whatever.doc>whatever.d
oc</A>
(Yes, that extra whatever.doc in the URL is on purpose. Microsoft sucks.)
<?php
#download.php:
#This header forces a download:
header("Content-type: application/octet-stream");
#This header convinces some browsers to prompt with whatever.doc instead
of download.php:
header("Content-disposition: $filename");
#There are about 6 more headers to convince other browser versions of
the same...
#Look in the code archives for them.
passthru("/secret/path/not/in/your/website/$filename);
?>
--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm