0

My PHP script forces a file to download, which all works fine, but when forcing zip files to download, they corrupt.

When I try and open the zip file locally it just converts from a .zip to a .zip.cpgz

If I download the file from a direct URL the zip file is fine, so I know it's only corrupting during the push/download phase.

Here's my code

    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"_zip_download.zip\"");
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-Description: File Transfer");
    header("Content-Length: " . filesize($zip_file));
Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
Daniel Williams
  • 2,195
  • 7
  • 32
  • 53
  • 1
    possible duplicate of [How to force file download with PHP](http://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php) – e4c5 Aug 21 '15 at 00:07

1 Answers1

1

For zip file you can set header("Content-Type: application/zip");

header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"_zip_download.zip\"");
header("Content-Length: " . filesize($zip_file));
readfile($zip_file);
exit;
Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47