Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP ZipArchive Corrupt in Windows
    primarykey
    data
    text
    <p>I am using PHP's ZipArchive class to create a zip file containing photos and then serve it up to the browser for download. Here is my code:</p> <pre><code>/** * Grabs the order, packages the files, and serves them up for download. * * @param string $intEntryID * @return void * @author Jesse Bunch */ public static function download_order_by_entry_id($intUniqueID) { $objCustomer = PhotoCustomer::get_customer_by_unique_id($intUniqueID); if ($objCustomer): if (!class_exists('ZipArchive')): trigger_error('ZipArchive Class does not exist', E_USER_ERROR); endif; $objZip = new ZipArchive(); $strZipFilename = sprintf('%s/application/tmp/%s-%s.zip', $_SERVER['DOCUMENT_ROOT'], $objCustomer-&gt;getEntryID(), time()); if ($objZip-&gt;open($strZipFilename, ZIPARCHIVE::CREATE) !== TRUE): trigger_error('Unable to create zip archive', E_USER_ERROR); endif; foreach($objCustomer-&gt;arrPhotosRequested as $objPhoto): $filename = PhotoCart::replace_ee_file_dir_in_string($objPhoto-&gt;strHighRes); $objZip-&gt;addFile($filename,sprintf('/press_photos/%s-%s', $objPhoto-&gt;getEntryID(), basename($filename))); endforeach; $objZip-&gt;close(); header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($strZipFilename)).' GMT', TRUE, 200); header('Cache-Control: no-cache', TRUE); header('Pragma: Public', TRUE); header('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT', TRUE); header('Content-Length: '.filesize($strZipFilename), TRUE); header('Content-disposition: attachment; filename=press_photos.zip', TRUE); header('Content-Type: application/octet-stream', TRUE); ob_start(); readfile($strZipFilename); ob_end_flush(); exit; else: trigger_error('Invalid Customer', E_USER_ERROR); endif; } </code></pre> <p>This code works really well with all browsers but IE. In IE, the file downloads correctly, but the zip archive is empty. When trying to extract the files, Windows tells me that the zip archive is corrupt. Has anyone had this issue before?</p> <p><strong>Edit</strong> Update: After suggestion from @profitphp, I changed my headers to this:</p> <pre><code>header("Cache-Control: public"); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); //header("Content-Description: File Transfer"); //header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=\"pressphotos.zip\""); //header("Content-Transfer-Encoding: binary"); header("Content-length: " . filesize($strZipFilename)); </code></pre> <p>Also, here is a screenshot of the error in Windows after opening with Firefox:</p> <p><img src="https://i.stack.imgur.com/7B2WA.png" alt="alt text"></p> <p>This error occurs in both IE and Firefox on Windows. It works fine in Mac. Also, in Windows, the filesize appears to be correct:</p> <p><img src="https://i.stack.imgur.com/1OblV.png" alt="alt text"></p> <p><strong>Edit #2</strong> This issue is sovled. See my answer below.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload