Re: downloading files
| From: | Aaron Todd | Date: | Fri, 20 Aug 2004 13:24:12 +0000 |
| Subject: | Re: downloading files | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194325@lists.php.net to get a copy of this message | ||
I have been using the following code to try to make it work:
<?php
$file = /home/site/member/filename.xxx";
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));
readfile($file);
?>
The webroot of my site is at: /var/www/html
So far this will create a new file on my computer where ever I want, but it
does not download the contents of the file.
Any suggestions?
Thanks,
Aaron
"Octavian Rasnita" <orasnita@fcc.ro> wrote in message
news:003d01c48616$a5133b40$142afea9@microsoft.com...
> You can put the files that need to be downloaded in a directory somewhere
> outside of the web server root, but in that case your PHP program will
> need
> to read the file and print it to the browser, and it will also need
> printing
> the HTTP headers:
>
> Content-type: application/octet-stream
> Content-disposition: attachment; file=$filename
> Content-length: xxx
> [blank line]
>
> Or you can put the files somewhere on the web server tree, protect the
> directory with .htaccess (username + password), and just put a simple link
> to those files.
> When someone will click that link, it will be asked for a username and
> password in a popup window that the browser will open.
>
> If you don't want to appear that window, you can set your server to
> redirect
> the user to a php script, for a certain Status code that is generated when
> authorization is required, and that PHP script can ask nice for a username
> and password that can be used then by the script to allow access to that
> file (but this way might be more complicated without real benefits).
>
> Teddy
>
> Teddy
>
> ----- Original Message -----
> From: "Aaron Todd" <aaloki88@hotmail.com>
> To: <php-general@lists.php.net>
> Sent: Thursday, August 19, 2004 8:30 PM
> Subject: [PHP] downloading files
>
>
>> I posted a simular question before and never really got an answer. The
> post
>> drifted off into some other valuable information, but I still have the
> same
>> question.
>>
>> I am trying to create a site with file downloads. The files on the
>> server
>> that are to be downloaded need to be protected somehow. I have already
>> created a login page for the site so users must log in. The download
> files
>> are in a directory protected by htaccess which it is my understanding
>> that
>> PHP can go underneath htaccess to get access to the files. My problem is
>> where do I put this directory? I was already told to put it outside the
> web
>> root directory, but I really dont know where the best place is.