RE: implementing downloads with php?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux