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初学者写及时补给skype用户充话费的小程序

其实加在一起有几十个,但因为需要操作的数据比较多,就在后面加了一段小程序来解决.可以处理昨天没有处理到的数据,具体如下:复制代码 代码如下:$handle = mysql_connect...

php函数与传递参数实例分析

本文实例讲述了函数的调用与函数定义语法,并讲解了关于函数中的变量以及向函数传递数值方法.分享给大家供大家参考。具体如下: 一、函数的基础 php提供了大量的函数,并且允许用户自定函数,p...

php curl操作API接口类完整示例

本文实例讲述了php curl操作API接口类。分享给大家供大家参考,具体如下: <?php namespace curl; /** * Created by Php...

php弹出提示框的是实例写法

php中弹出对话框的方法如下,一般,在提交信息后需要弹出对话框提示,之后可以自动关闭对话框,弹出对话框有下面集中方法,其实都是利用javascript中的alert()方法。提示结束后关...

PHP中使用循环实现的金字塔图形

今天学习了最基础的PHP条件和循环语句,最后老师提了几个问题,其中一个实现空心金字塔的图像比较好玩。 老师要让我们实现的是:      *   &...