dongwen9975 2017-04-06 12:04
浏览 20

如何使用Zend压缩多个文件(2)压缩?

Files are getting zipped..but once i extracting the zip file, the result is single file..not a multiple file.How to zip multiple file using zend filter(Zip)..?

Here is my code..

//zip part
        $filter = new Compress(array(
            'adapter' => 'Zip',
            'options' => array(
                'archive' => TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR. "download" . DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id.'.zip'
            )
        ));
        $file_list = scandir(TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR. "download". DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id);
        if(count($file_list) >2){
            foreach ($file_list as $file) {
              if (in_array($file, array(".",".."))) continue;
              $filter->filter(TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR. "download". DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id . DIRECTORY_SEPARATOR . $file);
            }
        }
        //zip end
  • 写回答

1条回答 默认 最新

  • dozc58418381 2017-04-06 15:45
    关注

    Every $filter->filter(…) invocation creates a new archive that contains only one file and the existing archive with the previous file gets overwritten. Solution:

    $filter = new Compress([
      'adapter' => 'Zip',
      'options' => [
        'archive' => TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR . 'download'
          . DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id . '.zip'
      ]
    ]);
    
    // assuming you _can_ create archive from the whole directory
    $filter->filter(TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR . 'download'
      . DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度