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 相关文章推荐
提问的智慧(2)
Oct 09 PHP
树型结构列出指定目录里所有文件的PHP类
Oct 09 PHP
php中截取字符串支持utf-8
Jan 18 PHP
php 读取shell管道传输过来的内容
Mar 01 PHP
解析PHP中empty is_null和isset的测试
Jun 29 PHP
php实现telnet功能示例
Apr 08 PHP
PHP命名空间(namespace)的使用基础及示例
Aug 18 PHP
PHP采用curl模仿用户登陆新浪微博发微博的方法
Nov 07 PHP
PHP记录页面停留时间的方法
Mar 30 PHP
php reset() 函数指针指向数组中的第一个元素并输出实例代码
Nov 21 PHP
Laravel向公共模板赋值方法总结
Jun 25 PHP
解决windows上php xdebug 无法调试的问题
Feb 19 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
php5.3以后的版本连接sqlserver2000的方法
2014/07/28 PHP
Linux下PHP安装mcrypt扩展模块笔记
2014/09/10 PHP
php合并数组中相同元素的方法
2014/11/13 PHP
thinkPHP框架乐观锁和悲观锁实例分析
2019/10/30 PHP
HTML Dom与Css控制方法
2010/10/25 Javascript
一个支持任意尺寸的图片上下左右滑动效果
2014/08/24 Javascript
jQuery结合HTML5制作的爱心树表白动画
2015/02/01 Javascript
详解JavaScript ES6中的模板字符串
2015/07/28 Javascript
javascript常用函数(1)
2015/11/04 Javascript
深入浅析react native es6语法
2015/12/09 Javascript
Angular使用Md5加密的解决方法
2017/09/16 Javascript
jQuery访问浏览器本地存储cookie、localStorage和sessionStorage的基本用法
2017/10/20 jQuery
详解jQuery中的easyui
2018/09/02 jQuery
tsconfig.json配置详解
2019/05/17 Javascript
vue 实现cli3.0中使用proxy进行代理转发
2019/10/30 Javascript
vue 开发之路由配置方法详解
2019/12/02 Javascript
vue中watch的用法汇总
2020/12/28 Vue.js
[01:58]2018DOTA2亚洲邀请赛趣味视频——交流
2018/04/03 DOTA
python实现中文分词FMM算法实例
2015/07/10 Python
基于Python数据可视化利器Matplotlib,绘图入门篇,Pyplot详解
2017/10/13 Python
Python reduce函数作用及实例解析
2020/05/08 Python
Pandas把dataframe或series转换成list的方法
2020/06/14 Python
Python 代码调试技巧示例代码
2020/08/11 Python
CSS3实现文本垂直排列的方法
2018/07/10 HTML / CSS
不可轻视HTML5!App三年内将被html5顶替彻底消失
2015/11/18 HTML / CSS
电子商务毕业生求职信
2013/11/10 职场文书
大学竞选班长演讲稿
2014/04/24 职场文书
物流专业专科生职业生涯规划书
2014/09/14 职场文书
领导干部整治奢华浪费之风思想汇报
2014/10/07 职场文书
领导干部作风建设总结
2014/10/23 职场文书
社会实践活动总结
2015/02/05 职场文书
个人德育工作总结
2015/03/05 职场文书
老乡聚会通知
2015/04/23 职场文书
2015年售后服务工作总结
2015/04/25 职场文书
2016年秋季开学典礼新闻稿
2015/11/25 职场文书
Python中Permission denied的解决方案
2021/04/02 Python