Saturday, December 09, 2006

File downloads in PHP

This is a simple code snippet. It will allow you to force the web-browser that is currently viewing your script to come up with a file-download box (and the a file on your system can be downloaded).

Here is the code:

//so only the data from the headers is sent
//dispable caching
header (”Cache-Control: must-revalidate, pre-check=0, post-check=0″);
header (”Content-Type: application/binary”);
header (”Content-Length: ” . filesize($export_long_name));
header (”Content-Disposition: attachment; filename=yourfile.ext”);

No comments: