pclzip压缩文件和解压的多种示例
2018-01-05 00:00
330 查看
本文介绍pclzip解压文件、压缩文件和列出压缩文件的列表多种示例方法,这是一个非常常用的功能,有时候需要用到压缩或解压,这个demo就是亲测过的。希望可以帮助你呢
演示一:添加文件到压缩文件 createAddZip("more.zip","test/ResponsiveSlides幻灯片效果/,test/二当家的.txt");//参数1 生成的压缩文件名称,参数2 要压缩的文件(多个文件逗号隔开) function createAddZip($zip_url, $files) { //添加文件到压缩文件 $files = getGb2312($files); set_time_limit(0); require_once("PclZip.class.php"); $zip = new PclZip($zip_url); $rs = $zip->create($files); if ($rs == 0) { die("Error : " . $zip->errorInfo(true)); } } 演示二:添加文件到压缩文件,并且替换相关路径 createReplaceZip("more.zip","test/ResponsiveSlides幻灯片效果/,test/二当家的.txt","test","zip");//参数2 要压缩的文件(多个文件逗号隔开) 参数3:移除的文件路径,参数4,:添加的文件路径 function createReplaceZip($zip_url, $files, $name, $name_replace) { //添加文件到压缩文件,并且替换相关路径 $files = getGb2312($files); set_time_limit(0); require_once("PclZip.class.php"); $zip = new PclZip($zip_url); $rs = $zip->create($files, PCLZIP_OPT_REMOVE_PATH, $name, PCLZIP_OPT_ADD_PATH, $name_replace); if ($rs == 0) { die("Error : " . $zip->errorInfo(true)); } } 演示三:解压压缩文件并且添加或移除解压后的文件路径 replacePathExtract("more.zip", "", "zip"); //参数2 添加路径,参数3 移除路径 function replacePathExtract($zip_url, $file_path, $file_path_remove) { //解压压缩文件并且添加或移除解压后的文件路径 set_time_limit(0); require_once("PclZip.class.php"); $zip = new PclZip($zip_url); $rs = $zip->extract(PCLZIP_OPT_PATH, $file_path, PCLZIP_OPT_REMOVE_PATH, $file_path_remove); //PCLZIP_OPT_PATH:添加路径,PCLZIP_OPT_REMOVE_PATH:移除原来的路径 } 演示四:添加文件到压缩文件,移除指定路径 removePathZip("more.zip", "test/js", "test"); //参数2 添加的路径,参数3 移除的路径 function removePathZip($zip_url, $files, $path_remove) { //添加文件到压缩文件,移除指定路径 $files = getGb2312($files); set_time_limit(0); require_once("PclZip.class.php"); $zip = new PclZip($zip_url); $rs = $zip->add($files, PCLZIP_OPT_REMOVE_PATH, $path_remove); //移除路径file } 演示五:列出压缩文件列表 showFilesList("more.zip"); function showFilesList($zip_url) { //列出压缩文件列表 require_once("PclZip.class.php"); $zip = new PclZip($zip_url); if (($list = $zip->listContent()) == 0) { die("Error : " . $zip->errorInfo(true)); } for ($i = 0; $i < sizeof($list); $i++) { for (reset($list[$i]); $key = key($list[$i]); next($list[$i])) { echo "File " . $i . " / [" . $key . "] = " . $list[$i][$key] . " "; } echo " "; } }
相关文章推荐
- pclzip压缩文件和解压的多种示例
- c#实现metro文件压缩解压示例
- pclzip 压缩文件与解压
- Python中使用tarfile压缩、解压tar归档文件示例
- Java实现文件压缩与解压的示例[zip格式,gzip格式]
- php用PclZip类压缩和解压文件(格式为ZIP)
- Swift实现文件压缩和解压示例代码
- U3D中C#压缩解压文件示例
- C#实现文件压缩与解压的方法示例【ZIP格式】
- Python中使用tarfile压缩、解压tar归档文件示例
- php中PclZip插件文件解压与压缩文件
- Delphi 7zip 示例调用7z.dll 压缩及解压.7z文件
- 《OD学hadoop》在LINUX下如何将tar压缩文件解压到指定的目录下
- Linux下压缩和解压文件
- 文件的压缩与解压(linux)
- Linux操作系统下常用压缩文件的解压方式
- 系统多种资源文件代码示例(例如一个系统同时具有中文简体,中文繁体,英文,日文等不同资源文件)(示例代码下载)
- 实现asp.net的文件压缩、解压、下载
- Python实现多级目录压缩与解压文件的方法
- Android--下载zip压缩文件并解压