php壓縮解壓縮檔案

2022-08-14 23:36:24 字數 1387 閱讀 2445

注 需要安裝zip擴充套件

/*** 壓縮單個檔案

* @method zip_file

* @param  string   $filename 檔名

* @return boolean             true|false

*/function zip_file(string $filename)

$zip=new ziparchive();

$zipname=basename($filename).'.zip';

//開啟指定壓縮包,不存在則建立,存在則覆蓋

if($zip->open($zipname,ziparchive::create|ziparchive::overwrite))else

}else

}// var_dump(zip_file('22.txt'));

// func_get_args

// test1.zip

/*** 多檔案壓縮

* @method zip_files

* @param  string    $zipname 壓縮包的名稱,.zip結尾

* @param  string     $files   需要壓縮檔案名,可以是多個

* @return boolean             true|false

*/function zip_files(string $zipname,...$files)

$zip=new ziparchive();

if($zip->open($zipname,ziparchive::create|ziparchive::overwrite))

}$zip->close();

return true;

}else

}// var_dump(zip_files('test1.zip','22.txt'));

// var_dump(zip_files('test2.zip','doupload.php','download.html','upload.html'));

/*** 解壓縮

* @method unzip_file

* @param  string     $zipname 壓縮包名稱

* @param  string     $dest    解壓到指定目錄

* @return boolean              true|false

*/function unzip_file(string $zipname,string $dest)

//檢測目標路徑是否存在

if(!is_dir($dest))

$zip=new ziparchive();

if($zip->open($zipname))else

}

解壓縮檔案

public static fastzip fz new fastzip 壓縮檔案 壓縮檔案的路徑與名稱 被壓縮的檔案路徑 解壓密碼 null代表無密碼 public static string filetozip string zipfilepath,string filepath,string ...

解壓縮檔案

using system using system.collections.generic using system.linq using system.text using system.threading.tasks using system.io namespace commonhelper ...

iOS檔案解壓縮 帶密碼解壓縮 壓縮檔案情況處理

ziparchive za ziparchive alloc init 1開啟檔案,並在記憶體中解壓 if za unzipopenfile zippath password 123 else nsfilemanager defaultmanager removeitematpath zippath...