头像

pclzip压缩文件和解压的多种演示

来源:http://school.sxbd100.com/plug/316.html 代码交流管理员 2018-04-18浏览(667)

本文介绍pclzip解压文件、压缩文件和列出压缩文件的列表多种示例方法。

程序员,你不是一个人;网站开发QQ群:136483411  在线充值,或联系QQ 304534221直接充值

pclzip压缩文件和解压的多种演示
分类:首页>>PHP/Mysql>>插件 阅读次数:668
查看演示 下载次数: 0

手机扫码访问:

下载资源 下载积分: 405

演示一:添加文件到压缩文件

createAddZip("more.zip","");//参数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/,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] . "<br />"; 

        } 

        echo "<br />"; 

    } 

}


标签: 压缩 解压
声明:本文为原创文章,如需转载,请注明来源school.sxbd100.com并保留原文链接:http://school.sxbd100.com/plug/316.html
如果您觉得本文的内容对您的学习有所帮助,您可以扫描下面的二维码请我喝杯茶,感谢!
alipay转账 alipay转账 扫扫加qq群

评论(0)


温馨提示:为规范评论内容,垃圾评论一律封号...

后面还有条评论,点击查看>>