我正在通过以下代码下载 zip 文件,没有任何错误,但下载的 zip 文件为空或损坏,大小始终约为 200 字节。即我无法打开那个 zip 文件。ZipArchive::getStatusString() 也显示“无错误”
代码是:
public function getzip(){
global $config;
$files=array();
if(isset($_COOKIE['hashes'])){
$hashes=explode(',',$_COOKIE['hashes']);
for ($i=0; $i <count($hashes); $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);
}
}