tkzo/zip-archiver

Easy to make zip archive in PHP.

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

This package is auto-updated.

Last update: 2024-12-22 01:19:47 UTC


README

Build Status GitHub tag Packagist Minimum PHP Version License

This package is intended for easy creation of ZIP archives.

This package is compliant with PSR-4, PSR-1, and PSR-2. If you notice compliance oversights, please send a patch via pull request.

Installation

To install ZipArchiver you can either clone this repository or you can use composer.

composer require tkzo/zip-archiver

Usage

e.g.)

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);

There is a complete example of this in example/example.php.

License

MIT License