I am successfully creating a zip archive. However, when I unzip then try to view the files in the unzipped archive on my desktop, only .doc files are corrupt. PDF, HTML, CSV, etc. all open fine.
Any ideas as to why only .doc files are being corrupted? This uses cakephp
The function:
$zip = new \ZipArchive();
$time = Time::now();
$t2 = $time->i18nFormat('yyyyMMddHHmmss');
$zipfilename = 'file' . $t2 . '.zip';
$zip->open('[path]' . $zipfilename, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
foreach($formData['docType'] as $doc) {
$file = $this->getFile($doc,$formData['id']);
$filepath = explode('/', $file);
$filename = end($filepath);
$zip->addFile($file, $filename);
}
$zip->close();
header('Content-type: application/zip');
header('Content-disposition: attachment; filename=' . $zipfilename);
ob_clean();
flush();
readfile('[path]' . $zipfilename);
exit();