php ZipArchive 压缩整个文件夹
// 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 压缩整个文件夹的更多相关文章
- albert1017 Linux下压缩某个文件夹(文件夹打包)
albert1017 Linux下压缩某个文件夹(文件夹打包) tar -zcvf /home/xahot.tar.gz /xahottar -zcvf 打包后生成的文件名全路径 要打包的目录例子:把 ...
- shell 批量压缩指定文件夹及子文件夹内图片
shell 批量压缩指定文件夹及子文件夹内图片 用户上传的图片,一般都没有经过压缩,造成空间浪费.因此须要编写一个程序,查找文件夹及子文件夹的图片文件(jpg,gif,png),将大于某值的图片进行压 ...
- python实现压缩当前文件夹下的所有文件
import os import zipfile def zipDir(dirpath, outFullName): ''' 压缩指定文件夹 :param dirpath: 目标文件夹路径 :para ...
- gulp插件实现压缩一个文件夹下不同目录下的js文件(支持es6)
gulp-uglify:压缩js大小,只支持es5 安装: cnpm: cnpm i gulp-uglify -D yarn: yarn add gulp-uglify -D 使用: 代码实现1:压缩 ...
- linux 压缩当前文件夹下所有文件
linux zip压缩.压缩当前文件夹下所有文件,压缩为a.zip.命令行的方法是怎样. zip -r fileName.zip 文件夹名 tar tar命令可以用来压缩打包单文件.多个文件.单个 ...
- Linux下压缩某个文件夹(文件夹打包)
tar -zcvf /home/xahot.tar.gz /xahottar -zcvf 打包后生成的文件名全路径 要打包的目录例子:把/xahot文件夹打包后生成一个/home/xahot.tar. ...
- 使用VC++压缩解压缩文件夹
前言 项目中要用到一个压缩解压缩的模块, 看了很多文章和源代码, 都不是很称心, 现在把我自己实现的代码和大家分享. 要求: 1.使用Unicode(支持中文). 2.使用源代码.(不使用静态或 ...
- Linux 压缩某个文件夹命令
tar -zcvf /home/xahot.tar.gz /xahot tar -zcvf 打包后生成的文件名全路径 要打包的目录 例子:把/xahot文件夹打包后生成一个/home/xahot.ta ...
- Delphi XE2 新增 System.Zip 单元, 可用一句话压缩整个文件夹了
内主要就是 TZipFile 类, 最方便使用的是它的类方法: TZipFile.ExtractZipFile() //解压 Zip 文件到指定文件夹 TZipFile.IsValid() //判断指 ...
随机推荐
- FrameWork内核解析之Handler消息机制(二)
阿里P7Android高级架构进阶视频(内含Handler视频讲解)免费学习请点击:https://space.bilibili.com/474380680 一.Handler 在Android开发的 ...
- 37-python基础-python3-字典的常用方法-keys()-values()-items()
有 3 个字典方法,它们将返回类似列表的值,分别对应于字典的键.值和键-值对:keys().values()和 items(). 这些方法返回的值不是真正的列表,它们不能被修改,没有append()方 ...
- C语言printf函数
#include<stdio.h> //int float double short char long int main() { //int printf(const char *for ...
- grep中正则表达式使用尖括号表示一个单词
比如 grep '\<bin\>' /etc/passwd --color
- POJ-1155 TELE 树形背包dp
dp[u][i]代表以u为根的子树选i个叶子的最大收益 那么dp[u][i]=max(dp[u][i],dp[v][k]+dp[u][i-k]-len) (1=<k<=i) 细节看代码: ...
- 让APK只包含指定的ABI(转)
转自:http://blog.csdn.net/justfwd/article/details/49308199 现在很多android第三方 sdk是以aar形式提供的,甚至是远程aar,如果这个s ...
- Linux系统关闭对ping命令做响应。
1.测试 ping 192.168.10.5 可以正常ping通, 2,修改 /proc/sys/net/ipv4/icmp_echo_ignore_all 文件的值=1 3.在测试 已经ping不 ...
- ansible-继续普通用户权限运行
ansible 远程以普通用户执行命令 1. ansible 10.0.0.1 -m raw -a "date" -u www 2.在ansible的主机配置文件中指定ssh_ ...
- centos 单用户登陆模式操作
在centos中因为安装java而配置 jdk环境变量的原因,对/etc/profile文件进行了编辑 错误的环境变量配置导致在第一次修改profile文件并保存后,执行source /etc/pro ...
- vue组件实例的生命周期
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...