PHP怎样解紧缩zip文件?(代码示例)
发布时间:09/01 来源:未知 浏览:
关键词:
PHP解紧缩zip文件
1、使用PHP施行文件解紧缩zip文件,前提前提,必然要肯定效劳器开启了zip拓展
2、封装的办法如下:
实例代码
<?php /** * 紧缩文件 * @param array $files 待紧缩文件 array('d:/test/1.txt','d:/test/2.jpg');【文件地址为绝对途径】 * @param string $filePath 输出文件途径 【绝对文件地址】 如 d:/test/new.zip * @return string|bool */ function zip($files, $filePath) { //检查参数 if (empty($files) || empty($filePath)) { return false; } //紧缩文件 $zip = new ZipArchive(); $zip->open($filePath, ZipArchive::CREATE); foreach ($files as $key => $file) { //检查文件可否存在 if (!file_exists($file)) { return false; } $zip->addFile($file, basename($file)); } $zip->close(); return true; } /** * zip解压办法 * @param string $filePath 紧缩包所在地址 【绝对文件地址】d:/test/123.zip * @param string $path 解压途径 【绝对文件名目途径】d:/test * @return bool */ function unzip($filePath, $path) { if (empty($path) || empty($filePath)) { return false; } $zip = new ZipArchive(); if ($zip->open($filePath) === true) { $zip->extractTo($path); $zip->close(); return true; } else { return false; } } ?>
相关教程引荐:《PHP教程》
以上就是PHP怎样解紧缩zip文件?(代码示例)的具体内容,更多请关注百分百源码网其它相关文章!