Tôi nhận được tệp zip được tải xuống bằng mã sau mà không có bất kỳ lỗi nào nhưng tệp zip đã tải xuống trống hoặc bị hỏng và kích thước luôn là khoảng 200 byte. tức là tôi không thể mở tệp zip đó. Cũng ZipArchive :: getStatusString() cũng được hiển thị "Không có lỗi"Nhận zip bị hỏng hoặc rỗng bằng ZipArchive php
code is:
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);
}
}
điều này khiến tôi sai. điều này có nghĩa là thư mục $ zipname không được tạo. Nhưng không nhận được thông báo "Không có gì trong giỏ" thay vì tải xuống tệp zip. –