[Discuss] web file download
Stephen Adler
adler at stephenadler.com
Tue Feb 28 19:09:23 EST 2012
Hi Blu,
I'm writing a web application which downloads files using PHP. The trick
to getting a file to download using your browser is to send it a key set
of header messages which tell the browser that a file is on its way.
I've poked around the web to find several example of the headers that
one needs to send, but as usual, there seems to be more under the
surface than the simple 3 line example.
The most comprehensive set of header commands I've seen to initiate a
file download is the following...
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="'.$Filename.'"');
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);
header('X-SendFile: '.$StorageDirectory.'/'.$UUID);
exit();
My question to the web experts is what is really needed to be sent using
the PHP header function in order to get a file across properly. I'm
wondering about the 'Expires:', 'Cache-Control:', and 'Pragma:' headers.
What are they needed for and how do they make the transfer work better.
Any general comments on this is greatly appreciated.
Thanks!
Steve.
More information about the Discuss
mailing list