Reputation: 33
I have the below code that creates a ZIP file, adds a file to it and then downloads to my computer.
$zip = new ZipArchive();
if ($zip->open('order_sheets.zip', ZipArchive::CREATE) === TRUE){
$zip->addFile($pdfFilePath);
}
$zip->close();
$file_url = 'order_sheets.zip';
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$file_url);
header('Content-Length: ' . filesize($file_url));
readfile($file_url);
All works good but the issue is, when opening the downloaded ZIP, it say's This folder is empty when it is not. If i right click and hit "Extract Here", the contents come out.
Anyone know why that is?
Upvotes: 0
Views: 462
Reputation: 400
The problem is with Windows' zip utility, which uses IBM850 encoding causing it to misinterpret some characters in internal filenames in the archive, including _
(underscore) as in your file.
See answer here: PHP ZipArchive Corrupt in Windows
Explained in PHP Manual user notes here: http://php.net/manual/en/ziparchive.addfile.php#95725
Upvotes: 1