php 解壓檔案與壓縮檔案

2021-09-01 02:23:07 字數 923 閱讀 1365

配置環境變數

然後cmd 輸入 php -m

檢視是否有zip 選項 沒有的話zip功能將無法使用

function zip_file(string $filename)

$zip = new ziparchive();

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

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

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

$zip->close();

return true;

} else }/*

* 多檔案壓縮

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

$zip = new ziparchive();

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

return true;

} else

$zip . close();

}/**

* 解壓縮

* @param string $zipname

* @param string $dest

* @return bool

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

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

if (!is_dir($dest))

$zip = new ziparchive();

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

}

壓縮檔案與解壓檔案

只引用sevenzipsharp就可以了,剩下兩個是動態引用的。壓縮 引用dll路徑 要壓縮到的路徑 檔案絕對路徑 密碼,沒有可輸入null public static void compressfile string dllfiledir,string dirpath,string filenam...

php壓縮解壓縮檔案

注 需要安裝zip擴充套件 壓縮單個檔案 method zip file param string filename 檔名 return boolean true false function zip file string filename zip new ziparchive zipname b...

gzip壓縮檔案 解壓檔案

解壓gzip壓縮格式檔案 eg 123.mms param source 原始檔 param target 目標檔案 public static void ungzipfile file source,string target throws exception gzin.close 關閉壓縮輸入流...