tkzo/

zip-archiver

PHP中制作ZIP归档文件非常简单。

v1.0.0 2021-09-21 17:54 UTC

This package is auto-updated.

Last update: 2024-09-22 00:51:11 UTC


README

Build Status GitHub tag Packagist Minimum PHP Version License

此包旨在轻松创建ZIP归档文件。

此包符合PSR-4PSR-1PSR-2规范。如果您发现符合规范的问题,请通过pull request发送补丁。

安装

要安装ZipArchiver,您可以通过克隆此存储库或使用composer进行。

composer require tkzo/zip-archiver

使用方法

例如)

use ZipArchiver\Archiver;

// Setup working directory.
$archiveTitle   = 'archive';
$tmpWorkingDir  = md5(uniqid() . $_SERVER['REQUEST_TIME_FLOAT']);
$tmpWorkingPath = sprintf('%s/%s/%s', sys_get_temp_dir(), $tmpWorkingDir, $archiveTitle);

// Make working directory.
@mkdir($tmpWorkingPath, 0777, true);

// Move the files you want to archive to a working directory.
rename('/path/to/file1.ext', sprintf('%s/%s', $tmpWorkingPath, 'file1.ext'));
rename('/path/to/file2.ext', sprintf('%s/%s', $tmpWorkingPath, 'file1.ext'));
rename('/path/to/file3.ext', sprintf('%s/%s', $tmpWorkingPath, 'file1.ext'));

// Sets the output path of the zip archive.
$zipPath = sprintf('%s/%s.zip', $tmpWorkingPath, $archiveTitle);

// Make zip archive.
Archiver::zipDir($tmpWorkingPath, $zipPath);

完整的示例可以在example/example.php中找到。

许可证

MIT许可证