I have used below code to download zip using ZipArchive by generating a pdf file from string. Random password is generated which is provided to use to open it.
$zip = new ZipArchive();
$file = sprintf('%s/%s', sys_get_temp_dir(), $zipFile);
if ($zip->open($file, ZipArchive::CREATE) === TRUE) {
$zip->addFromString($pdfFile, $stringPdf); //add file
$zip->setEncryptionName($pdfFile, ZipArchive::EM_AES_256, $pwd);
$zip->close();
header('Content-Description: File Download');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $zipFile . '"');
header("Pragma: no-cache");
header("Expires: 0");
header('Content-Length: \' . filesize($file).\'');
ob_end_clean();
flush();
if (readfile($file) !== false) {
unlink($file);
}
}
Th issue is the Zip with PDF is downloaded properly and also no error is generated in browser. Still not sure why the downloaded zip cannot be extracted. Not sure how to debug it or could be an issue. Would be great If anyone can advice.
Module Information as below is same on QA and Staging environment but still download zip is working on both but extracting just doesnt work on Staging. It just doesn't verify the password. What can be causing this environment issue, If any?
zip
Zip => enabled
Zip version => 1.19.2
Libzip headers version => 1.7.3
Libzip library version => 1.8.0
BZIP2 compression => Yes
XZ compression => Yes
ZSTD compression => No
AES-128 encryption => Yes
--
ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.7
Linked Version => 1.2.7
Directive => Local Value => Master Value
zlib.output_compression => Off => Off
zlib.output_compression_level => -1 => -1