无法从php函数下载zip文件

时间:2017-11-27 17:52:12

标签: php

我正在调用此函数来创建和下载zip。创建正在运行,但是当系统即将下载时我的屏幕会冻结,然后显示一堆抽象的文字而无需下载

function zipF(){
$track = $_POST['track'];
$cartid = $_POST['cartid'];

$zip = new ZipArchive;
    if ($zip->open('myzip.zip',  ZipArchive::CREATE)) {
        $notan = DataDB::getInstance()->select_from_where('order_image','cartid',$cartid);  
        foreach($notan as $row){
        $zip->addFile('../img/tempfil/'.$row['image'], $row['image']);
        }
        $zip->close();
        $archive_file_name ="myzip.zip";
       header("Content-type: application/zip"); 
       header("Content-Disposition: attachment; 
       filename=$archive_file_name");
       header("Content-length: " . filesize($archive_file_name));
       header("Pragma: no-cache"); 
       header("Expires: 0"); 
       readfile("$archive_file_name");
      echo '<div class="alert alert-danger">
                            <strong>Error!</strong> Problem with your order details.'.$track.'
            </div>';
       } else {
         echo 'Failed!';
       }
 }

0 个答案:

没有答案