php压缩文件下载后损坏,PHP ZipArchive在Windows中损坏

我正在使用PHP的ZipArchive类来创建一个包含照片的zip文件,然后将其提供给浏览器进行下载。这是我的代码:

/**

* 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->getEntryID(), time());

if ($objZip->open($strZipFilename, ZIPARCHIVE::CREATE) !== TRUE):

trigger_error('Unable to create zip archive', E_USER_ERROR);

endif;

foreach($objCustomer->arrPhotosRequested as $objPhoto):

$filename = PhotoCart::replace_ee_file_dir_in_string($objPhoto->strHighRes);

$objZip->addFile($filename,sprintf('/press_photos/%s-%s', $objPhoto->getEntryID(), basename($filename)));

endforeach;

$objZip->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;

}

这个代码对所有的浏览器都很好,但IE。在IE中,文件正确下载,但zip存档为空。当尝试提取文件时,Windows会告诉我zip存档已损坏。有人有这个问题吗?

编辑更新:从@profitphp的建议之后,我更改了我的头文件:

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));

另外,以下是使用Firefox打开Windows后的错误的屏幕截图:

IE和Firefox在Windows上都会出现此错误。它在Mac中正常工作。此外,在Windows中,文件大小似乎是正确的:

编辑#2这个问题是sovled。看下面我的回答

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值