Re: implementing downloads with php?

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

 



On 02 Apr 2015 at 22:51, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote: 

> 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 think you want something like this:

<?php

// This file could be called mydownloader.php

$file = $_POST['filename'];

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize ($file));

ob_clean ();
flush ();
readfile ($file);

?>


In my case, after validating the user's choices, I have this form in a webpage:


<form action="mydownloader.php" method="post">

<input name="filename" value='/path/to/file' type=hidden>

<p style="padding-top: 2em; padding-bottom: 2em;"><input type="submit" value="Download"></p>

</form>


You'll have to construct the value field, of course.

--
Cheers  --  Tim

-- 
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