PHP压缩文件夹 php
$path = PUBLIC_DIR.'/images/'; //待压缩文件夹父目录
$zipPath = PUBLIC_DIR.'/images_zip/'; //压缩文件保存目录 !is_dir($zipPath) ? mkdir($zipPath, 0755, true) : ''; // Initialize archive object
$zip = new ZipArchive(); $dir_list = scandir($path); if (empty($dir_list)) {
return false;
} foreach($dir_list as $dir_name) {
if ($dir_name == '.' || $dir_name == '..') {
continue;
}
$dir_path = $path.$dir_name; //待压缩目录
if (!is_dir($dir_path)) {
continue;
} $zipFile = $zipPath.$dir_name.'.zip'; //压缩包名称
$zip->open($zipFile, ZipArchive::CREATE | ZipArchive::OVERWRITE); $file_list = scandir($dir_path); //文件名
foreach ($file_list as $file_name) {
if ($file_name == '.' || $file_name == '..') {
continue;
} $zip->addFile($dir_path.'/'.$file_name, $file_name); //第二个参数使压缩文件名为待压缩文件原名(否则压缩包里会有多级目录) }
$zip->close(); }
待压缩文件夹:

压缩后压缩包:

打开压缩包看效果:

PHP压缩文件夹 php的更多相关文章
- C#压缩文件夹
using System;using System.Collections.Generic;using System.Text; ///第三方dllusing ICSharpCode.SharpZip ...
- C#利用SharpZipLib解压或压缩文件夹实例操作
最近要做一个项目涉及到C#中压缩与解压缩的问题的解决方法,大家分享. 这里主要解决文件夹包含文件夹的解压缩问题. )下载SharpZipLib.dll,在http://www.icsharpcode. ...
- Java使用线程池递归压缩文件夹下面的所有子文件
本文将介绍Java中利用线程池递归的方式压缩文件夹下面的所有子文件,具体方法如下: Gzip单个文件压缩 对于单个文件使用GZip压缩. package date0805.demo1; import ...
- C++复制、压缩文件夹
之前写过一篇用zlib库来压缩的,但zlib只能压缩文件,我需要压缩文件夹,要想压缩文件夹还得利用zlib库自己写代码,我是真的服了,一个开源库这么不好用. C++复制文件夹也是麻烦事,网上这篇文章: ...
- C#压缩文件夹坑~
dotNet疯狂之路No.29 今天很残酷,明天更残酷,后天很美好,但是绝大部分人是死在明天晚上,只有那些真正的英雄才能见到后天的太阳. We're here to put a dent in t ...
- .net压缩文件夹
1,引用:using System.IO.Packaging; 2,压缩文件的方法: /// <summary> /// 压缩文件夹到制定的路径 /// </summary> ...
- C#压缩文件,C#压缩文件夹,C#获取文件
using System; using System.Data; using System.Configuration; using System.Collections.Generic; using ...
- 使用7zip批量压缩文件夹到不同压缩包
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\" ...
- 简单测试Demo:如何用Java压缩文件夹和文件
一.直接贴出测试代码 package com.jason.zip; import java.io.File; import java.io.FileInputStream; import java.i ...
- Java 压缩文件夹工具类(包含解压)
依赖jar <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons ...
随机推荐
- Linux centos 下安装redis
一.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 二.选择安装文件 ...
- SQLServer 安装提示需要重启计算机的解决方案
处理方法:在开始-程序-运行中(或者直接windows+R件同时),输入regedit回车,在注册表中找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Con ...
- C2. Power Transmission (Hard Edition)(线段相交)
This problem is same as the previous one, but has larger constraints. It was a Sunday morning when t ...
- intel windows caffe加速
网址: https://github.com/BeFreeRoad/intel_caffe_windows 将intel caffe从linux平台移植到windows平台. 性能: 在虚拟机上测试可 ...
- laravel如何输出最后一条执行的SQL
\DB::connection()->enableQueryLog(); // 开启查询日志 \DB::table('xxx'); // 要查看的sql $queries = \DB::getQ ...
- 83)PHP,配置文件功能
首选配置文件应该在 我们的应用application目录中,这样针对每一应用,都有自己的配置文件. 我觉得配置文件的名字很有意思,首先是 名字.config.php 格式就是 return arr ...
- java5的静态导入import static
在Java 5中,import语句得到了增强,以便提供甚至更加强大的减少击键次数功能,虽然一些人争议说这是以可读性为代价的.这种新的特性成为静态导入. 1.静态导入的与普通import的区别: imp ...
- GCC与静态库、动态库
GCC 常用指令 1 man gcc gcc工作流程例如: gcc hello.c 1234567891011121314 //***第一步***gcc -E hello.c >hello.i ...
- asp.net mvcview界面does not contain a definition
在cshtml使用linq操作数据集,自动补全是可以使用Select,但是一直提示System.Collection.GenericList' does not contain a definitio ...
- UFT安装目录简单介绍
1.在安装的help目录下可查看UFT相关的文档 2.在samples/filght/app目录下可看到UFT自带的用作测试的软件