readfile()在服务器上不起作用,但在本地php上起作用

时间:2020-07-06 20:01:03

标签: server download local readfile

我正在生成一个.zip文件,然后使用php和readfile()函数强制下载该文件。它可以在本地正常运行,但不能在服务器中运行,在调用该函数时,它已损坏

这是代码,希望您能帮助我

$zip = new ZipArchive();
 
$filename = 'C'.$show['C'].'.zip';

 
if($zip->open($filename,ZIPARCHIVE::CREATE)===true) {
        $zip->addFile($show['C'],"C".basename($show['C']));
       
        $zip->addFile($show['O'],"O".basename($show['O']));
        $zip->addFile($show['T'],"T".basename($show['T']));

        $zip->addFile($oficio,"C-".basename($oficio));
         
       $zip->close();
}
else {
        echo 'Error creating '.$filename;
}
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=".$filename);
header('Content-Length: ' . filesize($filename));
 ob_clean();
 readfile($filename);
 unlink($filename);

0 个答案:

没有答案