NYCPHP Meetup

NYPHP.org

[nycphp-talk] File Download Question

Eddie Haber php at haberco.com
Thu Oct 20 13:23:32 EDT 2005


I have a file download area on my site. Users click a link, a JS pop-up
window pops with a meta-refresh tag that refreshes to the file to be
downloaded. The pop-up window also refreshes (reloads) the opener page.

Everything works great, except one problem. I am using a PHP script as a
gatekeeper/passthru for the file to be downloaded. Once the file download
begins, no other links on the browser (parent or pop-up) will resolve until
the download is over or is stopped. The second the download stops, any
clicked on link resolves.

The odd part is: If the meta-refresh in the pop-up goes directly to the zip
file, the browser can link away without problem. But if meta-refresh links
to the php script that dispenses the file, the links won't resolve during
download. Script is below.

Much appreciated! Thank you,
Eddie


<?

// a bunch of security checking

// filename (all are zip files)
$filename = "somepath/somefile.zip";

// commented headers below are
// alternate tries that didn't work

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

@readfile("$filename");
exit;

?>





More information about the talk mailing list