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 MsSql server时遇到的中文编码问题
Jun 11 PHP
深入理解php的MySQL连接类
Jun 07 PHP
解决FastCGI 进程超过了配置的活动超时时限的问题
Jul 03 PHP
使用Discuz关键词服务器实现PHP中文分词
Mar 11 PHP
PHP实现的MongoDB数据库操作类分享
May 12 PHP
Thinkphp搜索时首页分页和搜索页保持条件分页的方法
Dec 05 PHP
php实现的mongodb操作类
May 28 PHP
php ajax异步读取rss文档数据
Mar 29 PHP
php实现基于openssl的加密解密方法
Sep 30 PHP
PHP实现微信图片上传到服务器的方法示例
Jun 29 PHP
YII分模块加载路由的实现方法
Oct 01 PHP
Laravel框架控制器的request与response用法示例
Sep 30 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脚本数据库功能详解(下)
2006/10/09 PHP
php操作(删除,提取,增加)zip文件方法详解
2015/03/12 PHP
PHP可变变量学习小结
2015/11/29 PHP
weiphp微信公众平台授权设置
2016/01/04 PHP
PHP基于反射机制实现插件的可插拔设计详解
2016/11/10 PHP
php从数据库中获取数据用ajax传送到前台的方法
2018/08/20 PHP
客户端脚本中常常出现的一些问题和调试技巧
2007/01/09 Javascript
javascript中interval与setTimeOut的区别示例介绍
2014/03/14 Javascript
JavaScript入门基础
2015/08/12 Javascript
如何根据百度地图计算出两地之间的驾驶距离(两种语言js和C#)
2015/10/29 Javascript
基于Bootstrap实现Material Design风格表单插件 附源码下载
2016/04/18 Javascript
JS 数字转换为大写金额的简单实例
2016/08/04 Javascript
jQuery插件echarts去掉垂直网格线用法示例
2017/03/03 Javascript
canvas仿iwatch时钟效果
2017/03/06 Javascript
vue-cli项目中怎么使用mock数据
2017/09/27 Javascript
基于js中的存储键值对以及注意事项介绍
2018/03/30 Javascript
如何使用vuex实现兄弟组件通信
2018/11/02 Javascript
JS学习笔记之数组去重实现方法小结
2019/05/29 Javascript
详解基于原生JS验证表单组件xy-form
2019/08/20 Javascript
Python实现ping指定IP的示例
2018/06/04 Python
Python使用pyautogui模块实现自动化鼠标和键盘操作示例
2018/09/04 Python
基于Python在MacOS上安装robotframework-ride
2018/12/28 Python
python使用time、datetime返回工作日列表实例代码
2019/05/09 Python
Django实现分页显示效果
2019/10/31 Python
Tensorflow训练MNIST手写数字识别模型
2020/02/13 Python
django实现将修改好的新模型写入数据库
2020/03/31 Python
使用python matploblib库绘制准确率,损失率折线图
2020/06/16 Python
迎八一活动主题
2014/01/31 职场文书
银行工作检查书范文
2014/01/31 职场文书
2014幼儿园卫生保健工作总结
2014/12/05 职场文书
2014年绩效考核工作总结
2014/12/11 职场文书
美术教师个人工作总结
2015/02/06 职场文书
企业财务经理岗位职责
2015/04/08 职场文书
2015年学生资助工作总结
2015/05/25 职场文书
vue-router中hash模式与history模式的区别
2021/06/23 Vue.js
Win10 Anaconda安装python-pcl
2022/04/29 Servers