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


Posted in PHP onMay 26, 2010
/* 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 相关文章推荐
如何获得PHP相关资料
Oct 09 PHP
php中通过正则表达式下载内容中的远程图片的函数代码
Jan 10 PHP
php中file_get_content 和curl以及fopen 效率分析
Sep 19 PHP
php截取字符串函数分享
Feb 02 PHP
php中memcache 基本操作实例
May 17 PHP
php cli配置文件问题分析
Oct 15 PHP
PHP实现基于文本的摩斯电码生成器
Jan 11 PHP
PHP编程计算日期间隔天数的方法
Apr 26 PHP
Thinkphp 空操作、空控制器、命名空间(详解)
May 05 PHP
PHP实现限制IP访问及提交次数的方法详解
Jul 17 PHP
thinkphp集成前端脚手架Vue-cli的教程图解
Aug 30 PHP
thinkphp5使用无限极分类
Feb 18 PHP
PHP为表单获取的URL 地址预设 http 字符串函数代码
May 26 #PHP
PHP 创建标签云函数代码
May 26 #PHP
PHP 强制性文件下载功能的函数代码(任意文件格式)
May 26 #PHP
PHP 图像尺寸调整代码
May 26 #PHP
用PHP将网址字符串转换成超链接(网址或email)
May 25 #PHP
php 编写安全的代码时容易犯的错误小结
May 20 #PHP
Windows7下PHP开发环境安装配置图文方法
May 20 #PHP
You might like
php Ajax乱码
2008/04/09 PHP
PHP数组交集的优化代码分析
2011/03/06 PHP
php轻松实现中英文混排字符串截取
2014/05/28 PHP
JavaScript 事件对象的实现
2009/07/13 Javascript
javascript 二维数组的实现与应用
2010/03/16 Javascript
Javascript 通过json自动生成Dom的代码
2010/04/01 Javascript
Jquery基础教程之DOM操作
2015/08/19 Javascript
JavaScript html5 canvas绘制时钟效果(二)
2016/03/27 Javascript
jQuery实现漂亮实用的商品图片tips提示框效果(无图片箭头+阴影)
2016/04/16 Javascript
关于JS 预解释的相关理解
2016/06/28 Javascript
JS从数组中随机取出几个数组元素的方法
2016/08/02 Javascript
Angular 中 select指令用法详解
2016/09/29 Javascript
jquery文字填写自动高度的实现方法
2016/11/07 Javascript
基于jPlayer三分屏的制作方法
2016/12/21 Javascript
vue中使用localstorage来存储页面信息
2017/11/04 Javascript
jQuery+CSS实现的标签页效果示例【测试可用】
2018/08/14 jQuery
详解如何在vue项目中使用layui框架及采坑
2019/05/05 Javascript
简单了解vue中父子组件如何相互传递值(基础向)
2019/07/12 Javascript
Vue+iview+webpack ie浏览器兼容简单处理
2019/09/20 Javascript
Python中的列表知识点汇总
2015/04/14 Python
python+tkinter编写电脑桌面放大镜程序实例代码
2018/01/16 Python
centos 安装python3.6环境并配置虚拟环境的详细教程
2018/02/22 Python
python使用opencv驱动摄像头的方法
2018/08/03 Python
用python生成(动态彩色)二维码的方法(使用myqr库实现)
2019/06/24 Python
Django中使用极验Geetest滑动验证码过程解析
2019/07/31 Python
Python中使用socks5设置全局代理的方法示例
2020/04/15 Python
用 Django 开发一个 Python Web API的方法步骤
2020/12/03 Python
移动端开发HTML5页面点击按钮后出现闪烁或黑色背景的解决办法
2018/09/19 HTML / CSS
SmartBuyGlasses意大利:购买太阳镜、眼镜和隐形眼镜
2018/11/20 全球购物
美国室内和室外装饰花盆购物网站:ePlanters
2019/03/22 全球购物
销售业务实习自我鉴定
2013/09/23 职场文书
产品售后服务承诺书
2014/05/21 职场文书
社区志愿者活动方案
2014/08/18 职场文书
依法行政工作汇报材料
2014/10/28 职场文书
2014年计生协会工作总结
2014/11/21 职场文书
不会写演讲稿,快来看看这篇文章!
2019/08/06 职场文书