RE: implementing downloads with php?
| From: | Domain nikha . org | Date: | Fri, 03 Apr 2015 10:10:27 +0000 |
| Subject: | RE: implementing downloads with php? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324764@lists.php.net to get a copy of this message | ||
Jeffry Killen am Donnerstag, 2. April 2015 - 23:51:
> Hi;
>
> This is new territory for me a maybe a bit off topic but
> I am interested in finding out how to implement a downloading
> mechanism with php and without using ftp (if possible).
>
> I am understanding that http has a 'put' command. Is this the clue?
>
> When a file is downloaded from a site, like, for instance, a source
> code file from a directory. If the user does not have an ftp client,
> does
> the browser negotiate an ftp connection? As an application this could
> be used for file transfer via a web site.
>
> Thanks for time and attention
> JK
>
Hi Jeffry!
Thats a basic http header issue!
Try something like this:
$file = "name_of_the_file_to_download";
header("Content-Type: type/subtype; file=\"$file\"");
where "type/subtype" may be e.g. "image/jpeg" or whatever fits in your case,
then:
header("Content-Disposition: attachment/force-download; filename=\"$file\"");
and finaly:
echo file_get_contents('full_path/'.$file);
that tells the browser not to display the file contents, but to follow the users (per mime type)
settings for downloads (launch the internal filemanager, or automaticaly store in a predefiend
clients directory)
Hope this helps you,
Niklaus