Andrej Sýkora
Andrej Sýkora

Reputation: 13

Firefox 7 refuses to download file returned by PHP

after upgrading to Firefox 7, I can't download files I output via PHP on my sites.

An example:

Let's say I have link http://example.com/download/1 returning pretty normal 800KB .ZIP file, with:

header("Content-Type: application/octet-stream"); 
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");    
header("Content-Disposition: attachment; filename=" .trim($filename). "");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " .filesize($filePath). ")"); 
readfile($filePath);
flush();

Every possible browser, even older versions of Firefox, start downloading the file as usually. Firefox 7 throws "Corrupted Content Error".

Does anyone notice similiar behaviour? Any possible solutions?

Upvotes: 1

Views: 854

Answers (2)

Aziz
Aziz

Reputation: 20705

It seems that you have an extra ) in the Content-Length header

This:

header("Content-Length: " .filesize($filePath). ")"); 

should be

header("Content-Length: " .filesize($filePath). ""); 

Upvotes: 0

Pekka
Pekka

Reputation: 449425

You have a superfluous ) in the content-length field. That may screw up the file size that the browser expects from the download, and cause the error.

Upvotes: 3

Related Questions