[英]Yii - Downloaded zip file is corrupted
從Yii下載zip文件會導致zip文件損壞。 我可以打開zip,搜索其內容,但是數據已損壞。 在文件資源管理器中打開zip文件顯示該zip文件正常。 該問題僅在下載文件時出現:
$zip = new ZipArchive();
if($zip->open($zipname, ZIPARCHIVE::CREATE) === TRUE ){
// add stuff to zip
$res = $zip->addFile($a, $b);
}
Yii::app()->getRequest()->sendFile($zipname, file_get_contents($zipname), "application/zip", true);
我認為問題出在Yii的sendFile的$ content參數上。
content參數中應該包含什么內容,以便zip文件不會損壞?
謝謝
這樣解決了問題
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename='.basename($zipname));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($zipname));
ob_clean();
flush();
readfile($zipname);
exit;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.