[英]not extract .zip files after download using PHP
I download my back file with .zip
format using this PHP class: 我使用这个PHP类下载.zip
格式的后台文件:
public function download($file)
{
$filename = $this->dir . $file;
$fp = fopen($filename, "rb");
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/octet-stream");
header("Content-length: " . filesize($filename));
header("Content-disposition: attachment;filename = " . $file . "");
header("Content-Transfer-Encoding: binary");
readfile($filename);
ob_end_clean();
die(fpassthru($fp));
fclose($fp);
}
this worked and i downloaded .zip
file successful. 这工作,我下载.zip
文件成功。 but when i need to extract .zip
file using winrar i see this error: 但是当我需要使用winrar提取.zip
文件时,我看到了这个错误:
db-backup-2014-11-15_14-18-48-12.zip: The archive is either in unknown format or damaged
. db-backup-2014-11-15_14-18-48-12.zip: The archive is either in unknown format or damaged
。
in download : 在下载中:
in open: 在开放:
in extract : 在提取物中:
NOTE: my original file worked and fine extracted using winrar. 注意:我的原始文件工作,并使用winrar精细提取。
i think my problem is CRC32 = 0000000 (in screen one) because in original file is have a true value. 我认为我的问题是CRC32 = 0000000(在屏幕一),因为在原始文件中有一个真值。
how do fix this problem ?! 怎么解决这个问题?!
Your ZIP file is most likely corrupted because your PHP script contains white space after closing ?>
tag which pollutes ZIP content. 您的ZIP文件很可能已损坏,因为您的PHP脚本在关闭?>
标签后会包含空格,从而污染ZIP内容。 To solve this, remove PHP closing tag ?>
from your script that function download()
is part of (also check if you do not have leading white-spaces, placed before opening <?php
tag too) and your issue should be gone. 要解决这个问题,请从脚本中删除PHP结束标记?>
,函数download()
是其中的一部分(同时检查是否没有前导空格,在打开<?php
标记之前放置)并且您的问题应该消失。 If you include other scripts, check them for spaces too. 如果包含其他脚本,请检查它们是否也有空格。 In general ?>
tag should not be used, unless you are sure you need it it for known reason (which is very rare case). 一般来说,不应该使用?>
标签,除非你确定你因为已知的原因需要它(这种情况非常罕见)。
Try this download function instead : 请尝试使用此下载功能:
<?php
public function download($file) {
ob_end_clean();
$filename = $this->dir . $file;
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=". pathinfo($filename , PATHINFO_BASENAME));
header("Content-Length: " . filesize($filename ));
readfile($fileName);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.