博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php zip在线压缩文件,PHP Zip压缩 在线对文件进行压缩的函数_PHP教程
阅读量:7296 次
发布时间:2019-06-30

本文共 1417 字,大约阅读时间需要 4 分钟。

复制代码 代码如下:

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

http://www.bkjia.com/PHPjc/321861.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321861.htmlTechArticle复制代码 代码如下: /* creates a compressed zip file */ function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and ove...

转载地址:http://lsynm.baihongyu.com/

你可能感兴趣的文章
多线程
查看>>
extract-text-webpack-plugin 的使用及安装
查看>>
POJ 1408:Fishnet
查看>>
MariaDB的二进制包安装方法
查看>>
POJ 1703 Find them, Catch them
查看>>
线程死锁
查看>>
文件描述符fd、文件指针fp和vfork()
查看>>
【转】C++ const用法 尽可能使用const
查看>>
Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间
查看>>
WPF(Trigger)
查看>>
bzoj 1011 近似估计
查看>>
Index
查看>>
第二次作业
查看>>
MySQL自学2018/05/02-数据类型
查看>>
新一代的树莓派3版本——Raspberry Pi 3 发布了
查看>>
PPT模板中的”书签”
查看>>
机器学习概述
查看>>
5、Python函数
查看>>
MOSS2010单点登录
查看>>
洛谷 P1217 [USACO1.5]回文质数 Prime Palindrome
查看>>