如何在 PHP 中压缩文件夹?
我们可以使用 PHP ZipArchive 类来压缩和解压 PHP 中的文件夹。自 PHP 5.3 起,此类为内置类。对于 Windows 用户,需要在 php.ini 中启用 php_zip.dll。
示例
<?php
//Enter the name of directory
$pathdir = "Directory Name/";
//Enter the name to creating zipped directory
$zipcreated = "test.zip";
//Create new zip class
$newzip = new ZipArchive;
if($newzip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) {
$dir = opendir($pathdir);
while($file = readdir($dir)) {
if(is_file($pathdir.$file)) {
$newzip -> addFile($pathdir.$file, $file);
}
}
$newzip ->close();
}
?>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP