pclzip 压缩文件与解压

类PclZip.class.php下载:PclZip.rar

<?php
header("Content-type: text/html; charset=utf-8");

function createAddZip($zip_url, $files) { //添加文件到压缩文件
    $files = getZipGbk($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));
    }
}

function createReplaceZip($zip_url, $files, $name, $name_replace) { //添加文件到压缩文件,并且替换相关路径
    $files = getZipGbk($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));
    }
}

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:移除原来的路径
}

function removePathZip($zip_url, $files, $path_remove) { //添加文件到压缩文件,移除指定路径
    $files = getZipGbk($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
}

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 />";
    }
}

function getZipGbk($file) {
    $arr = explode(",", $file);
    foreach ($arr as $v) {
        $names[] = iconv('UTF-8', 'GB2312', $v);
    }
    return implode(",", $names);
}

//演示一:添加文件到压缩文件
//createAddZip("more.zip","test/ResponsiveSlides幻灯片效果/,test/素材火帮助.txt");//参数1 生成的压缩文件名称,参数2 要压缩的文件(多个文件逗号隔开)
// createAddZip("haha.zip","a.jpg,a.php,a.txt");
//演示二:添加文件到压缩文件,并且替换相关路径
//createReplaceZip("more.zip","test/ResponsiveSlides幻灯片效果/,test/素材火帮助.txt","test","zip");//参数2 要压缩的文件(多个文件逗号隔开) 参数3:移除的文件路径,参数4,:添加的文件路径
// createReplaceZip("haha.zip","b.txt","txt","zip");
//演示三:解压压缩文件并且添加或移除解压后的文件路径
//replacePathExtract("more.zip", "", "zip"); //参数2 添加路径,参数3 移除路径

//演示四:添加文件到压缩文件,移除指定路径
//removePathZip("more.zip", "test/js", "test"); //参数2 添加路径,参数3 移除路径

//演示五://列出压缩文件列表

showFilesList("haha.zip");

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值