I'm trying to make php download a .zip file using this code:
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Length: ' . filesize($file));
readfile($file);
$file is right.
I have two problem with this script:
If I use
header('Content-Length: ' . filesize($file));
the download is corrupt with 0 bytes file. If I comment this line, the download looks good on ubuntu.If I use mac OS to download this file, after opening the .zip it extracts .cpgz file (for what I read is when the zip is corrupt)
I've tried all kind of headers to make this work, but the problem is always on that header. My question is: how can I make this work on all OS?