I have a PHP script that creates a Zip Archive and then passes it to the browser for download.
This can be easily done via HTTP Response Headers
header('Pragma: no-cache');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0, public')
header('Content-Type: application/zip')
header('Content-Length: ' . filesize($zipPath))
header('Content-Disposition: attachment; filename=filename.zip')
header('Content-Transfer-Encoding: binary')
echo file_get_contents($zipPath);
The file is correctly downloaded. I can also open it. However, when I check the downloaded file mime-type
, it tells me : application/octet-stream
instead of application/zip
.
For file mime-type detection, I use the following snippet :
$pathToDownloadedFile = 'somewhere-on-disk';
$file = finfo_open(FILEINFO_MIME_TYPE);
var_dump(
file_exists($pathToDownloadedFile),
finfo_file($file, $pathToDownloadedFile)
);
which dumps out :
true
application/octet-stream
I googled the problem but with no luck.
Any piece of help would be very appreciated.