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

yipeiwu_com6年前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中header的用法详解

 header() is used to send raw HTTP headers. See the HTTP/1.1 specification for more info...

PHP5.0 TIDY_PARSE_FILE缓冲区溢出漏洞的解决方案

漏洞说明 不得不再次吐槽一下exploit-db对exp审核的质量,这个exp仍然不能触发漏洞,修改第一个参数则可以触发,我给出的poc是一个可以触发php漏洞的,问题出现在php_ti...

php使用CutyCapt实现网页截图保存的方法

本文实例讲述了php使用CutyCapt实现网页截图保存的方法。分享给大家供大家参考,具体如下: 网页截图这个功能大家可能用到最多的就是QQ截图,或利用asp.net来实现截图,其实我们...

thinkphp框架实现删除和批量删除

thinkphp框架实现删除和批量删除

本文实例讲一下如何用thinkphp实现数据的删除和批量删除吧。 预期效果图:   原谅博主对照片的处理是如此的草率吧。。。 仍然是 通过MVC模式进行拆分: 首先是视图部...

PHP实现简单搜歌的方法

本文实例讲述了PHP实现简单搜歌的方法。分享给大家供大家参考。具体实现方法如下: <form name="" method="post" action=""> <i...