// Get real path for our folder
$rootPath = realpath('folder-to-zip'); // Initialize archive object
$zip = new ZipArchive();
$zip->open('file.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE); // Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
); foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1); // Add current file to archive
$zip->addFile($filePath, $relativePath);
}
} // Zip archive will be created only after closing object
$zip->close();

php ZipArchive 压缩整个文件夹的更多相关文章

  1. albert1017 Linux下压缩某个文件夹(文件夹打包)

    albert1017 Linux下压缩某个文件夹(文件夹打包) tar -zcvf /home/xahot.tar.gz /xahottar -zcvf 打包后生成的文件名全路径 要打包的目录例子:把 ...

  2. shell 批量压缩指定文件夹及子文件夹内图片

    shell 批量压缩指定文件夹及子文件夹内图片 用户上传的图片,一般都没有经过压缩,造成空间浪费.因此须要编写一个程序,查找文件夹及子文件夹的图片文件(jpg,gif,png),将大于某值的图片进行压 ...

  3. python实现压缩当前文件夹下的所有文件

    import os import zipfile def zipDir(dirpath, outFullName): ''' 压缩指定文件夹 :param dirpath: 目标文件夹路径 :para ...

  4. gulp插件实现压缩一个文件夹下不同目录下的js文件(支持es6)

    gulp-uglify:压缩js大小,只支持es5 安装: cnpm: cnpm i gulp-uglify -D yarn: yarn add gulp-uglify -D 使用: 代码实现1:压缩 ...

  5. linux 压缩当前文件夹下所有文件

    linux zip压缩.压缩当前文件夹下所有文件,压缩为a.zip.命令行的方法是怎样. zip  -r fileName.zip  文件夹名 tar tar命令可以用来压缩打包单文件.多个文件.单个 ...

  6. Linux下压缩某个文件夹(文件夹打包)

    tar -zcvf /home/xahot.tar.gz /xahottar -zcvf 打包后生成的文件名全路径 要打包的目录例子:把/xahot文件夹打包后生成一个/home/xahot.tar. ...

  7. 使用VC++压缩解压缩文件夹

    前言   项目中要用到一个压缩解压缩的模块, 看了很多文章和源代码,  都不是很称心, 现在把我自己实现的代码和大家分享. 要求: 1.使用Unicode(支持中文). 2.使用源代码.(不使用静态或 ...

  8. Linux 压缩某个文件夹命令

    tar -zcvf /home/xahot.tar.gz /xahot tar -zcvf 打包后生成的文件名全路径 要打包的目录 例子:把/xahot文件夹打包后生成一个/home/xahot.ta ...

  9. Delphi XE2 新增 System.Zip 单元, 可用一句话压缩整个文件夹了

    内主要就是 TZipFile 类, 最方便使用的是它的类方法: TZipFile.ExtractZipFile() //解压 Zip 文件到指定文件夹 TZipFile.IsValid() //判断指 ...

随机推荐

  1. C++ STL rope 可持久化平衡树 (可持久化数组)

    官方文档好像 GG 了. rope 不属于标准 STL,属于扩展 STL,来自 pb_ds 库 (Policy-Based Data Structures). 基本操作: #include <e ...

  2. 9.Jmeter自定义Sample(自定义测试内容)完成测试

    问题:在某些场景下我们会发现Jmeter里面提供的各种Sample不能满足自己的需求,应为这个世界上的压力测试的逻辑本来就是千变万化的,所以这个时候我们如果自己实现一套测试逻辑(当Jmeter的基本e ...

  3. git清理工作区

    git clean -f 这将删除所有未被追踪的文件 git rev-list

  4. PHP正则表达式中的反斜线

    PHP反斜线再正则表达式中的使用 <?php $str = 'hello\world'; $pattern = '/hello\\\\world/'; preg_match($pattern,$ ...

  5. ansible了解

    基础知识: ansible简介 ansible 是个什么东西呢?基于 Python paramiko 开发,分布式,无需客户端,轻量级,配置语法使用 YMAL 及 Jinja2模板语言,更强的远程命令 ...

  6. DDCTF 北京地铁

    这周打了ddctf,被打成了dd 北京地铁题目给了一张北京地铁图,提示如下:Color Threshold 提示:AES ECB密钥为小写字母提示2:密钥不足位用\0补全提示3:不要光记得隐写不看图片 ...

  7. ubuntu安装goland

    安装goland 首先下载goland https://www.jetbrains.com/zh/go/specials/go/go.html?utm_source=baidu&utm_med ...

  8. 博客中引入了gitment评论系统

    官方github地址:https://github.com/imsun/gitment 官方中文说明地址:https://imsun.net/posts/gitment-introduction/ 官 ...

  9. 在egg中配置cors

    在egg中配置 cors(跨域) 第一步,安装 egg-cors npm i egg-cors --save 第二步,配置 cors 在config/plugin.js文件下添加: exports.c ...

  10. 2018-2-13-win10-uwp-活动磁贴

    title author date CreateTime categories win10 uwp 活动磁贴 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...