我通过以下代码下载zip文件,没有任何错误,但下载的zip文件为空或已损坏,大小总是大约200字节.
即我无法打开该zip文件.
ZipArchive :: getStatusString()也显示“No error”
代码是:
public function getzip(){
global $config;
$files=array();
if(isset($_COOKIE['hashes'])){
$hashes=explode(',',$_COOKIE['hashes']);
for ($i=0; $i
array_push($files,$config["domain"]."/download/".$hashes[$i]);
}
}
if(count($files)){
$zipname='basket.zip';
$zip = new ZipArchive;
$zip->open($zipname,ZipArchive::CREATE);
foreach ($files as $key=>$value ) {
$zip->addFile($value);
}
$status=$zip->getStatusString();
$zip->close();
if(!$zipname)
{
echo "Nothing in Basket";
}
else
{ header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition:attachment; filename='.basename($zipname));
header('Content-Length:'.filesize($zipname));
readfile($zipname);
}
}