文章来源:http://www.cnblogs.com/hello-tl/p/7661222.html

<?php

# 文件字符集
header("Content-type: text/html; charset=utf-8"); class TL_ZIP{
# web 跟
private $TL_ROOT; # zip包 目录
private $TL_DOWNLOAD; # zip文件名
private $TL_zipName; public function __construct(){
# 设置web根目录
$this->TL_ROOT = str_replace("\\", '/', dirname(__FILE__) . "/"); # 设置zip目录
$this->TL_DOWNLOAD = str_replace("\\", '/', dirname(__FILE__)) . "/DOWNLOAD/";
} # 设置 压缩包名称
public function getZipName($zipName){
# 判断一下文件名是否合法
$this->TL_zipName = $this->TL_DOWNLOAD . $zipName . ".zip";
return true;
} # 获取 压缩包名称
public function setZipName(){
return $this->TL_zipName;
} # 生成压缩包
public function createZip($arrFiles){
# 判断是否是数组
if(!is_array($arrFiles)){
return false;
} # 判断是否设置文件名 如果没有设定文件名 我就自己生成一个 哼!!!!
if(!$this->TL_zipName){
$this->TL_zipName = $this->TL_DOWNLOAD . date('YmdHis') . rand(111111111,999999999) . ".zip";
} # 定义zip文件名
$zipName = $this->TL_zipName; # 调用zip类
$zipClass = new ZipArchive();
if($zipClass->open($zipName, ZIPARCHIVE::CREATE) !== TRUE) {
return false;
}
foreach($arrFiles as $path){ # 判断是否是文件
if(is_file($this->TL_ROOT.$path)){ # 把文件加入到压缩包中
$zipClass->addFile($this->TL_ROOT.$path, basename($this->TL_ROOT.$path));
}
}
$zipClass->close();
return $zipName;
}
} $zipObj = new TL_ZIP();
$zipObj->createZip(
array(
'从设定的跟目录开始写文件地址',
'从设定的跟目录开始写文件地址',
'从设定的跟目录开始写文件地址'
)
);

文章来源:http://www.cnblogs.com/hello-tl/p/7661222.html

PHP:压缩 Zip的更多相关文章

  1. 在线压缩zip

    <?php //验证密码 $password = "test"; ?> <html> <head> <meta http-equiv=&q ...

  2. java zip API实现压缩和解压缩zip包

    package zip; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io ...

  3. Linux中解压、压缩 ZIP文件

    解压 unzip -o -d /home/v-gazh myfile.zip # 把myfile.zip文件解压到 /home/v-gazh/ # -o:不提示的情况下覆盖文件: # -d:-d /h ...

  4. Linux下的压缩zip,解压缩unzip命令详解及实例

    实例:压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip ====================== ...

  5. asp.net 文件压缩zip下载

     今天分享下昨天做的一个东西 asp.net 的文件  zip 批量下载,首先你需要去 到http://dotnetzip.codeplex.com这个站点下载zip 的包,在里面找到 Ionic.Z ...

  6. C# .NET 使用第三方类库DotNetZip解压/压缩Zip rar文件

    DotNetZip on CodePlex: http://dotnetzip.codeplex.com/ 详细的可以看源代码……总之感觉比SharpZipLib好用.而且DotNetZip支持VB, ...

  7. 【转】ubuntu下解压缩zip,tar,tar.gz和tar.bz2文件

    原文网址:http://blog.sina.com.cn/s/blog_5da93c8f0101h1uj.html 在Linux下面如何去压缩文件或者目录呢? 在这里我们将学习zip, tar, ta ...

  8. Linux下的压缩zip,解压缩unzip命令具体解释及实例

    实例:压缩server上当前文件夹的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前文件夹 unzip filename.zip ================= ...

  9. java压缩zip文件中文乱码问题(转——作者:riching)

    本人遇到了同样的问题,用了以下方案,奇迹般的解决了.我很纳闷为什么,经理说:好读书,不求甚解,不要问为什么... 用java来打包文件生成压缩文件,有两个地方会出现乱码 1.内容的中文乱码问题,这个问 ...

  10. POI导出大量数据的简单解决方案(附源码)-Java-POI导出大量数据,导出Excel文件,压缩ZIP(转载自iteye.com)

    说明:我的电脑 2.0CPU 2G内存 能够十秒钟导出 20W 条数据 ,12.8M的excel内容压缩后2.68M 我们知道在POI导出Excel时,数据量大了,很容易导致内存溢出.由于Excel ...

随机推荐

  1. bzoj 3052: [wc2013]糖果公园【树上带修改莫队】

    参考:http://blog.csdn.net/lych_cys/article/details/50845832 把树变成dfs括号序的形式,注意这个是不包含lca的(除非lca是两点中的一个) 然 ...

  2. 利用爬虫将Yuan先生的博客文章爬取下来

    由于一次巧遇,我阅读了Yuan先生的一篇博客文章,感觉从Yuan先生得博客学到很多东西,很喜欢他得文章.于是我就关注了他,并且想阅读更多出自他手笔得博客文章,无奈,可能Yuan先生不想公开自己得博客吧 ...

  3. failed to push some refs to 'https://gitee.com/ftl_663/java-shop.git'

    1.git init 2.git add . 3.git commit  -m "init" 4.git remote add origin  https://gitee.com/ ...

  4. bzoj 1858: [Scoi2010]序列操作 || 洛谷 P2572

    记一下:线段树占空间是$2^{ceil(log2(n))+1}$ 这个就是一个线段树区间操作题,各种标记的设置.转移都很明确,只要熟悉这类题应该说是没有什么难度的. 由于对某区间set之后该区间原先待 ...

  5. Magento Order 状态详解

    流程图:

  6. HttpURLConnection教程

    1.Class Overview An URLConnection for HTTP (RFC 2616) used to send and receive data over the web. Da ...

  7. MVP架构模式

    概念解释 MVP是Model(数据) View(界面) Presenter(表现层)的缩写,它是MVC架构的变种,强调Model和View的最大化解耦和单一职责原则 Model:负责数据的来源和封装, ...

  8. L 裁纸片 贪心 + 模拟

    https://biancheng.love/contest-ng/index.html#/123/problems 如果只是输出最小的值,那么好办,a升序,b降序,这样是最优的. 但是需要次数,这就 ...

  9. sql语句添加一列标示,然后进行分页。

    ,) , sum(Score) as Score ,Student_NO,Student_Name into #a2_tab from ksy_stu_ScoreInfo GROUP BY Stude ...

  10. LN : leetcode 646 Maximum Length of Pair Chain

    lc 646 Maximum Length of Pair Chain 646 Maximum Length of Pair Chain You are given n pairs of number ...