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程序
Oct 09 PHP
php 日期时间处理函数小结
Dec 18 PHP
php session劫持和防范的方法
Nov 12 PHP
php将csv文件导入到mysql数据库的方法
Dec 24 PHP
PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
Sep 22 PHP
php微信公众账号开发之前五个坑(一)
Sep 18 PHP
php微信公众号js-sdk开发应用
Nov 28 PHP
理清PHP在Linxu下执行时的文件权限方法
Jun 07 PHP
PHP基于rabbitmq操作类的生产者和消费者功能示例
Jun 16 PHP
thinkPHP5框架闭包函数与子查询传参用法示例
Aug 02 PHP
浅谈PHP之ThinkPHP框架使用详解
Jul 21 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 IPV6正则表达式验证代码
2010/02/16 PHP
php中关于普通表单多文件上传的处理方法
2011/03/25 PHP
PHP中限制IP段访问、禁止IP提交表单的代码
2011/04/23 PHP
PHP使用Mysql事务实例解析
2014/09/08 PHP
php给一组指定关键词添加span标签的方法
2015/03/31 PHP
验证坐标在某坐标区域内php代码
2016/10/08 PHP
laravel框架上传图片实现实时预览功能
2019/10/14 PHP
js判断两个日期是否相等的方法
2013/09/10 Javascript
js螺旋动画效果的具体实例
2013/11/15 Javascript
IE浏览器不支持getElementsByClassName的解决方法
2014/08/27 Javascript
简单实现js选项卡切换效果
2016/02/03 Javascript
JavaScript实现图片自动加载的瀑布流效果
2016/04/11 Javascript
关于动态生成dom绑定事件失效的原因及解决方法
2016/08/06 Javascript
js获取腾讯视频ID的方法
2016/10/03 Javascript
Jquery 整理元素选取、常用方法一览表
2016/11/26 Javascript
vue如何判断dom的class
2018/04/26 Javascript
通过jquery的ajax请求本地的json文件方法
2018/08/08 jQuery
Vue自定义组件的四种方式示例详解
2020/02/28 Javascript
vue与iframe之间的信息交互的实现
2020/04/08 Javascript
vue开发简单上传图片功能
2020/06/30 Javascript
toString.call()通用的判断数据类型方法示例
2020/08/28 Javascript
js实现简单抽奖功能
2020/11/24 Javascript
OpenLayers3加载常用控件使用方法详解
2020/09/25 Javascript
[43:58]DOTA2-DPC中国联赛定级赛 LBZS vs SAG BO3第一场 1月8日
2021/03/11 DOTA
Python数据库的连接实现方法与注意事项
2016/02/27 Python
python3.x上post发送json数据
2018/03/04 Python
详解程序意外中断自动重启shell脚本(以Python为例)
2019/07/26 Python
python每天定时运行某程序代码
2019/08/16 Python
Python基于numpy模块实现回归预测
2020/05/14 Python
opencv+pyQt5实现图片阈值编辑器/寻色块阈值利器
2020/11/13 Python
VLAN和VPN有什么区别?分别实现在OSI的第几层?
2014/12/23 面试题
食品行业求职人的自我评价
2014/01/19 职场文书
物控部经理职务说明书
2014/02/25 职场文书
安全生产目标责任书
2014/04/14 职场文书
夫妻忠诚协议范文
2014/11/16 职场文书
暂停营业通知
2015/04/25 职场文书