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 文件在线解压缩的函数代码

相关文章

phpwind中的数据库操作类

<?php /*来源:phpwind.net*/ Class DB { var $query_num = 0; function&...

Linux下ZendOptimizer的安装与配置方法

内容:  在装的好的Red Hat Linux 9 + Apache 2.0.55 + MySQ...

PHP实现AES256加密算法实例

本文实例讲述了PHP实现AES256加密算法的方法,是较为常见的一种加密算法。分享给大家供大家参考。具体如下: aes.class.php文件如下: <?php /*...

php 数组的一个悲剧?

复制代码 代码如下: $a=1; $b=2; $t = array( array('a', 'string', $field['a']), // 名称 if($a==$b){array(...

PHP使用HTML5 FormData对象提交表单操作示例

PHP使用HTML5 FormData对象提交表单操作示例

本文实例讲述了PHP使用HTML5 FormData对象提交表单操作。分享给大家供大家参考,具体如下: 这是HTML5中新增的一个Api,他能以表单对象作为参数,自动的把表单的数据打包,...