Re: Generating "download" pages [message #186406 is a reply to message #186405] |
Sat, 19 July 2014 16:36 |
Tim Streater
Messages: 328 Registered: September 2010
Karma:
|
Senior Member |
|
|
In article <b_wyv.50770$OC3(dot)15102(at)fx18(dot)iad>, Lew Pitcher
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
> Research has shown conflicting advice wrt the necessary headers, the order
> of the headers, the presence or absence of the web page HTML, the PHP
> functions required to send the file, etc.
Here's what I do to send a file:
<?php
$file = '/path/to/somefile.zip';
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);
?>
and this works for me. The file containing this PHP is the action of a
<form> which is submitted when the user clicks a button.
--
"The idea that Bill Gates has appeared like a knight in shining armour to
lead all customers out of a mire of technological chaos neatly ignores
the fact that it was he who, by peddling second-rate technology, led them
into it in the first place." - Douglas Adams
|
|
|