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下特殊命令集锦
1.ifconfig -a | grep enp0 | cut -d : -f 1 //按照:进行切割网络文件名 如:ifconfig `ifconfig -a | grep enp0 | cut ...
- Scapy-ARPspoof学习
layout title tag date post Scapy模块学习之ARP欺骗 Python 2018-05-08 from scapy.all import Ether,ARP,sendp,g ...
- memcached_高可用
memcached高可用 一.magent 1.安装 cd /usr/local/mkdir ./magentcd ./magentwget -c http://memagent.googlecode ...
- Work Scheduling(带反悔的贪心)
https://www.luogu.org/problem/P2949 题目描述 Farmer John has so very many jobs to do! In order to run th ...
- 5)void万能指针
函数参数为空,定义函数时,可以使用void来修饰:int fun(void) 函数没有返回值:void fun(void) 不同定义void类型的普通变量:void a //原因是,无法确定类 ...
- python中使用自定义类实例作为字典的key
python中dict类型的key值要求是不可变类型,通常来说,我们一般采用int或者str类型来作为字典的key,但是在某些场景中,会造成一定的麻烦. 如我们有一个处理http Request的规则 ...
- Mysql Sql 语句练习题 (50道)
MySql 语句练习50题 表名和字段 –1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_ ...
- django项目总结_20191128
django项目总结_20191128 ##################### 1,这个项目分为四个部分: 用户模块 商品模块 购物车模块 订单模块 2,这个项目用到的技术: redis cele ...
- OpenCV C++常用功能介绍
显示图片 IplImage* img = cvLoadImage("-/temp.jpeg", 1); //create a window to display the image ...
- vscode中的live-server配置https?
json文件中使用绝对路径添加证书 "liveServer.settings.https": { "enable": true, "cert" ...