【问题标题】:Zip folder first then allow user to download it首先压缩文件夹然后允许用户下载它
【发布时间】:2015-05-31 10:48:56
【问题描述】:

在我的网站上,我希望有一个链接可以压缩包含其内容的特定文件夹,然后允许用户下载它。它将用于下载捆绑的文件。

【问题讨论】:

    标签: php download zip rar


    【解决方案1】:

    试试这个代码:

     $files[] = base_url().'uploads/'.$names->file_name;
    

    将您的文件传递到这个 $files[] 数组中。

    $zip = new ZipArchive();  
        $tmp_file = tempnam('.','');
        $zip->open($tmp_file, ZipArchive::CREATE);   
        foreach($files as $file)
        {      //echo $file; exit;
            $download_file = file_get_contents($file); 
    
            $zip->addFromString(basename($file),$download_file); 
    
    
        }
        $zip->close();
    
        header('Content-disposition: attachment; filename=project_files.zip');
        header('Content-type: application/zip');
        readfile($tmp_file);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 2015-10-07
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多