php 檔案壓縮

來源:互聯網
上載者:User

標籤:檔案壓縮 php

PclZip檔案壓縮實現(推薦)

      我在做項目是的時候有個打包下載的需求:把上傳的多個檔案壓縮成一個檔案並下載,我用的比較強大的PclZip類實現的。我的用的是thinkphp3.2架構開發的,具體實現代碼如下

 /**    * 壓縮檔    * @param $zipName  壓縮的檔案名稱    * @param $fileName 要壓縮的檔案路徑的數組或字串    *  @param  $savePath  要儲存的路徑    * @return bool    */public function createZip($zipName,$fileName,$savePath){    //載入類       import("Org.Io.PclZip");       $archive = new \PclZip($zipName);       $list = $archive->create($fileName,PCLZIP_OPT_REMOVE_ALL_PATH);   //壓縮檔       if($list == 0){           return false;       }       //建立目錄,不存在就建立       if( !is_dir( $savePath)) {           mkdir( $savePath);       }       //檢查檔案是否存在       if(!file_exists($zipName)){           return false;       }       //移動檔案   create方法不能指定壓縮檔儲存路徑,預設是儲存在目前的目錄。       rename ($zipName,$savePath.$zipName);       return $savePath.$zipName;   }

其他參考資料:http://blog.csdn.net/gumanren/article/details/5520173


其他實現方式

1.PHP內建ZIP壓縮、解壓縮類ZipArchiv使用指南  :

    http://www.jb51.net/article/61678.htm

    http://www.cnblogs.com/keleyu/p/4273120.html

2.PHP壓縮與解壓Zip(PHPZip類)

   http://www.oschina.net/code/snippet_167936_6898





php 檔案壓縮

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.