PHP Zip压缩 在线对文件进行压缩的函数

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

//close the zip -- done!
$zip->close();

//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
/***** Example Usage ***/
$files=array('file1.jpg', 'file2.jpg', 'file3.gif');
create_zip($files, 'myzipfile.zip', true);

PHP Zip 文件在线解压缩的函数代码

相关文章

两个开源的Php输出Excel文件类

1.php-excel php-excel is a very simple library for generating excel documents from php on-the...

采集邮箱的php代码(抓取网页中的邮箱地址)

复制代码 代码如下: <?php $url='//www.jb51.net'; //这个网页里绝对含有邮件地址。 $content=file_get_contents($url);...

QueryPath PHP 中的jQuery

官方主页  http://querypath.org/ QP API 手册  http://api.querypath.org/docs/ QueryPath(QP...

PHP转盘抽奖接口实例

本文实例讲述了PHP转盘抽奖接口的实现方法。分享给大家供大家参考。具体如下: 这里的转盘抽奖随机返回一个转盘角度,概率可自己定义 lottery_get.php接口文件如下: 复制代码...

PHP中批量生成静态html(命令行下运行PHP)

PHP中批量生成静态html(命令行下运行PHP)

众所周知,大部分网站的新闻资讯或商品信息都是静态页面。这样做的好处主要是为了:1、加快访问速度,避免过多的操作数据库;2、SEO优化,便于搜索引擎收录。 本示例围绕 CMS 系统的静态页...