2014-09-05 41 views
2

我寫這篇文章的代碼從我的圖片創建一個zip文件如何在codeigniter中壓縮文件?

 $path = '/path/to/file/icon1.png'; 
     $path2 = '/path/to/file/icon2.png'; 
     $this->zip->read_file($path); 
     $this->zip->read_file($path2); 
     $this->zip->archive('/root/myarchive.zip'); 

現在我想添加使用add_dir例如Image一個目錄,然後添加$path$path2到該文件夾​​,然後創建一個檔案(默認CI這些圖像保存爲zip文件的根目錄)

回答

3

從文檔:

$這個 - > zip-> add_dir()


允許您添加目錄。通常這個函數是不必要的,因爲當你使用$ this-> zip-> add_data()時你可以將數據放入文件夾中,但是如果你想創建一個空文件夾,你可以這樣做。例如:

$this->zip->add_dir('myfolder'); // Creates a folder called "myfolder" 

簡單的,你可以在前面加上目錄名的路徑:

$path = '/path/to/file/icon1.png'; 
$this->zip->add_data('myfolder/' . $path, file_get_contents($path)); 

如果你想使用$this->zip->read_file()和維護文件的目錄結構,通過TRUE(布爾)在第二個參數。 - 說的DOC

$path = '/path/to/photo.jpg'; 
$this->zip->read_file($path, TRUE); 

在上面的例子中,photo.jpg將被放在兩個文件夾內:路徑/到/

+0

謝謝你,它的工作.. – 2017-08-16 04:13:12

+1

非常歡迎,高興來幫你 :)) – 2017-08-16 15:20:07