|
@@ -4,10 +4,22 @@
|
|
|
|
|
|
|
|
[](https://packagist.org/packages/nelexa/zip)
|
|
[](https://packagist.org/packages/nelexa/zip)
|
|
|
[](https://packagist.org/packages/nelexa/zip)
|
|
[](https://packagist.org/packages/nelexa/zip)
|
|
|
|
|
+[](https://php.net/)
|
|
|
|
|
+[](https://codeclimate.com/github/Ne-Lexa/php-zip/coverage)
|
|
|
[](https://packagist.org/packages/nelexa/zip)
|
|
[](https://packagist.org/packages/nelexa/zip)
|
|
|
|
|
|
|
|
-Features:
|
|
|
|
|
----------
|
|
|
|
|
|
|
+Table of contents
|
|
|
|
|
+-----------------
|
|
|
|
|
+- [Features](#Features)
|
|
|
|
|
+- [Requirements](#Requirements)
|
|
|
|
|
+- [Installation](#Installation)
|
|
|
|
|
+- [Examples](#Examples)
|
|
|
|
|
+- [Documentation](#Documentation)
|
|
|
|
|
+ + [Open Zip Archive](#Documentation-Open-Zip-Archive)
|
|
|
|
|
+ + [Get Zip Entries](#Documentation-Open-Zip-Entries)
|
|
|
|
|
+ + [Add Zip Entries](#Documentation-Add-Zip-Entries)
|
|
|
|
|
+
|
|
|
|
|
+### <a name="Features"></a> Features
|
|
|
- Opening and unzipping zip files.
|
|
- Opening and unzipping zip files.
|
|
|
- Create zip files.
|
|
- Create zip files.
|
|
|
- Update zip files.
|
|
- Update zip files.
|
|
@@ -20,42 +32,38 @@ Features:
|
|
|
- Support `ZIP64` (size > 4 GiB or files > 65535 in a .ZIP archive).
|
|
- Support `ZIP64` (size > 4 GiB or files > 65535 in a .ZIP archive).
|
|
|
- Support archive alignment functional [`zipalign`](https://developer.android.com/studio/command-line/zipalign.html).
|
|
- Support archive alignment functional [`zipalign`](https://developer.android.com/studio/command-line/zipalign.html).
|
|
|
|
|
|
|
|
-Requirements
|
|
|
|
|
-------------
|
|
|
|
|
|
|
+### <a name="Requirements"></a> Requirements
|
|
|
- `PHP` >= 5.5 (64 bit)
|
|
- `PHP` >= 5.5 (64 bit)
|
|
|
- Optional php-extension `bzip2` for BZIP2 compression.
|
|
- Optional php-extension `bzip2` for BZIP2 compression.
|
|
|
- Optional php-extension `openssl` or `mcrypt` for `WinZip Aes Encryption` support.
|
|
- Optional php-extension `openssl` or `mcrypt` for `WinZip Aes Encryption` support.
|
|
|
|
|
|
|
|
-Installation
|
|
|
|
|
-------------
|
|
|
|
|
|
|
+### <a name="Installation"></a> Installation
|
|
|
`composer require nelexa/zip:^3.0`
|
|
`composer require nelexa/zip:^3.0`
|
|
|
|
|
|
|
|
-Samples
|
|
|
|
|
--------
|
|
|
|
|
|
|
+### <a name="Examples"></a> Examples
|
|
|
```php
|
|
```php
|
|
|
-// create archive
|
|
|
|
|
|
|
+// create new archive
|
|
|
$zipFile = new \PhpZip\ZipFile();
|
|
$zipFile = new \PhpZip\ZipFile();
|
|
|
-$zipFile->addFromString("zip/entry/filename", "Is file content")
|
|
|
|
|
- ->addFile("/path/to/file", "data/tofile")
|
|
|
|
|
- ->addDir(__DIR__, "to/path/")
|
|
|
|
|
- ->saveAsFile($outputFilename)
|
|
|
|
|
- ->close();
|
|
|
|
|
|
|
+$zipFile
|
|
|
|
|
+ ->addFromString("zip/entry/filename", "Is file content")
|
|
|
|
|
+ ->addFile("/path/to/file", "data/tofile")
|
|
|
|
|
+ ->addDir(__DIR__, "to/path/")
|
|
|
|
|
+ ->saveAsFile($outputFilename)
|
|
|
|
|
+ ->close();
|
|
|
|
|
|
|
|
// open archive, extract, add files, set password and output to browser.
|
|
// open archive, extract, add files, set password and output to browser.
|
|
|
-$zipFile->openFile($outputFilename)
|
|
|
|
|
- ->extractTo($outputDirExtract)
|
|
|
|
|
- ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
|
|
|
|
|
- ->addFromString('dir/file.txt', 'Test file')
|
|
|
|
|
- ->withNewPassword('password')
|
|
|
|
|
- ->outputAsAttachment('library.jar');
|
|
|
|
|
|
|
+$zipFile
|
|
|
|
|
+ ->openFile($outputFilename)
|
|
|
|
|
+ ->extractTo($outputDirExtract)
|
|
|
|
|
+ ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
|
|
|
|
|
+ ->addFromString('dir/file.txt', 'Test file')
|
|
|
|
|
+ ->withNewPassword('password')
|
|
|
|
|
+ ->outputAsAttachment('library.jar');
|
|
|
```
|
|
```
|
|
|
Other examples can be found in the `tests/` folder
|
|
Other examples can be found in the `tests/` folder
|
|
|
|
|
|
|
|
-Documentation
|
|
|
|
|
--------------
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+### <a name="Documentation"></a> Documentation
|
|
|
|
|
+###### <a name="Documentation-Open-Zip-Archive"></a> Open Zip Archive
|
|
|
Open zip archive from file.
|
|
Open zip archive from file.
|
|
|
```php
|
|
```php
|
|
|
$zipFile = new \PhpZip\ZipFile();
|
|
$zipFile = new \PhpZip\ZipFile();
|
|
@@ -63,26 +71,67 @@ $zipFile->openFile($filename);
|
|
|
```
|
|
```
|
|
|
Open zip archive from data string.
|
|
Open zip archive from data string.
|
|
|
```php
|
|
```php
|
|
|
-$data = file_get_contents($urlOrFile);
|
|
|
|
|
$zipFile = new \PhpZip\ZipFile();
|
|
$zipFile = new \PhpZip\ZipFile();
|
|
|
-$zipFile->openFromString($filename);
|
|
|
|
|
|
|
+$zipFile->openFromString($stringContents);
|
|
|
```
|
|
```
|
|
|
Open zip archive from stream resource.
|
|
Open zip archive from stream resource.
|
|
|
```php
|
|
```php
|
|
|
$stream = fopen($filename, 'rb');
|
|
$stream = fopen($filename, 'rb');
|
|
|
-$zipFile = \PhpZip\ZipFile::openFromStream($stream);
|
|
|
|
|
|
|
+
|
|
|
|
|
+$zipFile = new \PhpZip\ZipFile();
|
|
|
|
|
+$zipFile->openFromStream($stream);
|
|
|
|
|
+###### <a name="Documentation-Open-Zip-Entries"></a> Get Zip Entries
|
|
|
```
|
|
```
|
|
|
Get num entries.
|
|
Get num entries.
|
|
|
```php
|
|
```php
|
|
|
-$count = $zipFile->count();
|
|
|
|
|
-// or
|
|
|
|
|
$count = count($zipFile);
|
|
$count = count($zipFile);
|
|
|
|
|
+// or
|
|
|
|
|
+$count = $zipFile->count();
|
|
|
```
|
|
```
|
|
|
Get list files.
|
|
Get list files.
|
|
|
```php
|
|
```php
|
|
|
$listFiles = $zipFile->getListFiles();
|
|
$listFiles = $zipFile->getListFiles();
|
|
|
|
|
+
|
|
|
|
|
+// Example result:
|
|
|
|
|
+//
|
|
|
|
|
+// $listFiles = [
|
|
|
|
|
+// 'info.txt',
|
|
|
|
|
+// 'path/to/file.jpg',
|
|
|
|
|
+// 'another path/'
|
|
|
|
|
+// ];
|
|
|
```
|
|
```
|
|
|
-Foreach zip entries.
|
|
|
|
|
|
|
+Get entry contents.
|
|
|
|
|
+```php
|
|
|
|
|
+// $entryName = 'path/to/example-entry-name.txt';
|
|
|
|
|
+
|
|
|
|
|
+$contents = $zipFile[$entryName];
|
|
|
|
|
+```
|
|
|
|
|
+Checks whether a entry exists.
|
|
|
|
|
+```php
|
|
|
|
|
+// $entryName = 'path/to/example-entry-name.txt';
|
|
|
|
|
+
|
|
|
|
|
+$hasEntry = isset($zipFile[$entryName]);
|
|
|
|
|
+```
|
|
|
|
|
+Check whether the directory entry.
|
|
|
|
|
+```php
|
|
|
|
|
+// $entryName = 'path/to/';
|
|
|
|
|
+
|
|
|
|
|
+$isDirectory = $zipFile->isDirectory($entryName);
|
|
|
|
|
+```
|
|
|
|
|
+Extract all files to directory.
|
|
|
|
|
+```php
|
|
|
|
|
+$zipFile->extractTo($directory);
|
|
|
|
|
+```
|
|
|
|
|
+Extract some files to directory.
|
|
|
|
|
+```php
|
|
|
|
|
+$extractOnlyFiles = [
|
|
|
|
|
+ "filename1",
|
|
|
|
|
+ "filename2",
|
|
|
|
|
+ "dir/dir/dir/"
|
|
|
|
|
+];
|
|
|
|
|
+$zipFile->extractTo($directory, $extractOnlyFiles);
|
|
|
|
|
+```
|
|
|
|
|
+Iterate zip entries.
|
|
|
```php
|
|
```php
|
|
|
foreach($zipFile as $entryName => $dataContent){
|
|
foreach($zipFile as $entryName => $dataContent){
|
|
|
echo "Entry: $entryName" . PHP_EOL;
|
|
echo "Entry: $entryName" . PHP_EOL;
|
|
@@ -90,7 +139,7 @@ foreach($zipFile as $entryName => $dataContent){
|
|
|
echo "-----------------------------" . PHP_EOL;
|
|
echo "-----------------------------" . PHP_EOL;
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
-Iterator zip entries.
|
|
|
|
|
|
|
+or
|
|
|
```php
|
|
```php
|
|
|
$iterator = new \ArrayIterator($zipFile);
|
|
$iterator = new \ArrayIterator($zipFile);
|
|
|
while ($iterator->valid())
|
|
while ($iterator->valid())
|
|
@@ -105,58 +154,54 @@ while ($iterator->valid())
|
|
|
$iterator->next();
|
|
$iterator->next();
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
-Checks whether a entry exists.
|
|
|
|
|
-```php
|
|
|
|
|
-$boolValue = $zipFile->hasEntry($entryName);
|
|
|
|
|
-```
|
|
|
|
|
-Check whether the directory entry.
|
|
|
|
|
-```php
|
|
|
|
|
-$boolValue = $zipFile->isDirectory($entryName);
|
|
|
|
|
-```
|
|
|
|
|
-Set password to all encrypted entries.
|
|
|
|
|
-```php
|
|
|
|
|
-$zipFile->setPassword($password);
|
|
|
|
|
-```
|
|
|
|
|
-Set password to concrete zip entry.
|
|
|
|
|
-```php
|
|
|
|
|
-$zipFile->setEntryPassword($entryName, $password);
|
|
|
|
|
-```
|
|
|
|
|
Get comment archive.
|
|
Get comment archive.
|
|
|
```php
|
|
```php
|
|
|
-$commentArchive = $zipFile->getComment();
|
|
|
|
|
|
|
+$commentArchive = $zipFile->getArchiveComment();
|
|
|
```
|
|
```
|
|
|
Get comment zip entry.
|
|
Get comment zip entry.
|
|
|
```php
|
|
```php
|
|
|
$commentEntry = $zipFile->getEntryComment($entryName);
|
|
$commentEntry = $zipFile->getEntryComment($entryName);
|
|
|
```
|
|
```
|
|
|
|
|
+Set password for read encrypted entries.
|
|
|
|
|
+```php
|
|
|
|
|
+$zipFile->withReadPassword($password);
|
|
|
|
|
+```
|
|
|
Get entry info.
|
|
Get entry info.
|
|
|
```php
|
|
```php
|
|
|
$zipInfo = $zipFile->getEntryInfo('file.txt');
|
|
$zipInfo = $zipFile->getEntryInfo('file.txt');
|
|
|
|
|
+
|
|
|
echo $zipInfo . PHP_EOL;
|
|
echo $zipInfo . PHP_EOL;
|
|
|
|
|
+
|
|
|
|
|
+// Output:
|
|
|
// ZipInfo {Path="file.txt", Size=9.77KB, Compressed size=2.04KB, Modified time=2016-09-24T19:25:10+03:00, Crc=0x4b5ab5c7, Method="Deflate", Attributes="-rw-r--r--", Platform="UNIX", Version=20}
|
|
// ZipInfo {Path="file.txt", Size=9.77KB, Compressed size=2.04KB, Modified time=2016-09-24T19:25:10+03:00, Crc=0x4b5ab5c7, Method="Deflate", Attributes="-rw-r--r--", Platform="UNIX", Version=20}
|
|
|
|
|
+
|
|
|
print_r($zipInfo);
|
|
print_r($zipInfo);
|
|
|
-//PhpZip\Model\ZipInfo Object
|
|
|
|
|
-//(
|
|
|
|
|
-// [path:PhpZip\Model\ZipInfo:private] => file.txt
|
|
|
|
|
-// [folder:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
-// [size:PhpZip\Model\ZipInfo:private] => 10000
|
|
|
|
|
-// [compressedSize:PhpZip\Model\ZipInfo:private] => 2086
|
|
|
|
|
-// [mtime:PhpZip\Model\ZipInfo:private] => 1474734310
|
|
|
|
|
-// [ctime:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
-// [atime:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
-// [encrypted:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
-// [comment:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
-// [crc:PhpZip\Model\ZipInfo:private] => 1264235975
|
|
|
|
|
-// [method:PhpZip\Model\ZipInfo:private] => Deflate
|
|
|
|
|
-// [platform:PhpZip\Model\ZipInfo:private] => UNIX
|
|
|
|
|
-// [version:PhpZip\Model\ZipInfo:private] => 20
|
|
|
|
|
-// [attributes:PhpZip\Model\ZipInfo:private] => -rw-r--r--
|
|
|
|
|
-//)
|
|
|
|
|
|
|
+
|
|
|
|
|
+// Output:
|
|
|
|
|
+// PhpZip\Model\ZipInfo Object
|
|
|
|
|
+// (
|
|
|
|
|
+// [path:PhpZip\Model\ZipInfo:private] => file.txt
|
|
|
|
|
+// [folder:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
+// [size:PhpZip\Model\ZipInfo:private] => 10000
|
|
|
|
|
+// [compressedSize:PhpZip\Model\ZipInfo:private] => 2086
|
|
|
|
|
+// [mtime:PhpZip\Model\ZipInfo:private] => 1474734310
|
|
|
|
|
+// [ctime:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
+// [atime:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
+// [encrypted:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
+// [comment:PhpZip\Model\ZipInfo:private] =>
|
|
|
|
|
+// [crc:PhpZip\Model\ZipInfo:private] => 1264235975
|
|
|
|
|
+// [method:PhpZip\Model\ZipInfo:private] => Deflate
|
|
|
|
|
+// [platform:PhpZip\Model\ZipInfo:private] => UNIX
|
|
|
|
|
+// [version:PhpZip\Model\ZipInfo:private] => 20
|
|
|
|
|
+// [attributes:PhpZip\Model\ZipInfo:private] => -rw-r--r--
|
|
|
|
|
+// )
|
|
|
```
|
|
```
|
|
|
Get info for all entries.
|
|
Get info for all entries.
|
|
|
```php
|
|
```php
|
|
|
$zipAllInfo = $zipFile->getAllInfo();
|
|
$zipAllInfo = $zipFile->getAllInfo();
|
|
|
|
|
+
|
|
|
print_r($zipAllInfo);
|
|
print_r($zipAllInfo);
|
|
|
|
|
+
|
|
|
//Array
|
|
//Array
|
|
|
//(
|
|
//(
|
|
|
// [file.txt] => PhpZip\Model\ZipInfo Object
|
|
// [file.txt] => PhpZip\Model\ZipInfo Object
|
|
@@ -171,90 +216,77 @@ print_r($zipAllInfo);
|
|
|
//
|
|
//
|
|
|
// ...
|
|
// ...
|
|
|
//)
|
|
//)
|
|
|
|
|
+
|
|
|
|
|
+###### <a name="Documentation-Add-Zip-Entries"></a> Add Zip Entries
|
|
|
```
|
|
```
|
|
|
-Extract all files to directory.
|
|
|
|
|
-```php
|
|
|
|
|
-$zipFile->extractTo($directory);
|
|
|
|
|
-```
|
|
|
|
|
-Extract some files to directory.
|
|
|
|
|
-```php
|
|
|
|
|
-$extractOnlyFiles = ["filename1", "filename2", "dir/dir/dir/"];
|
|
|
|
|
-$zipFile->extractTo($directory, $extractOnlyFiles);
|
|
|
|
|
-```
|
|
|
|
|
-Get entry content.
|
|
|
|
|
-```php
|
|
|
|
|
-$data = $zipFile->getEntryContent($entryName);
|
|
|
|
|
-```
|
|
|
|
|
-Edit zip archive
|
|
|
|
|
-```php
|
|
|
|
|
-$zipOutputFile = $zipFile->edit();
|
|
|
|
|
-```
|
|
|
|
|
-Close zip archive.
|
|
|
|
|
-```php
|
|
|
|
|
-$zipFile->close();
|
|
|
|
|
-```
|
|
|
|
|
-#### Class `\PhpZip\ZipOutputFile` (create, update, extract)
|
|
|
|
|
-Create zip archive.
|
|
|
|
|
|
|
+Adding a file to the zip-archive.
|
|
|
```php
|
|
```php
|
|
|
-$zipOutputFile = new \PhpZip\ZipOutputFile();
|
|
|
|
|
|
|
+// entry name is file basename.
|
|
|
|
|
+$zipFile->addFile($filename);
|
|
|
// or
|
|
// or
|
|
|
-$zipOutputFile = \PhpZip\ZipOutputFile::create();
|
|
|
|
|
-```
|
|
|
|
|
-Open zip file from update.
|
|
|
|
|
-```php
|
|
|
|
|
-$filename = "file.zip";
|
|
|
|
|
-$zipOutputFile = \PhpZip\ZipOutputFile::openFromFile($filename);
|
|
|
|
|
-```
|
|
|
|
|
-or
|
|
|
|
|
-```php
|
|
|
|
|
-// initial ZipFile
|
|
|
|
|
-$zipFile = \PhpZip\ZipFile::openFromFile($filename);
|
|
|
|
|
|
|
+$zipFile->addFile($filename, null);
|
|
|
|
|
|
|
|
-// Create output stream from update zip file
|
|
|
|
|
-$zipOutputFile = new \PhpZip\ZipOutputFile($zipFile);
|
|
|
|
|
-// or
|
|
|
|
|
-$zipOutputFile = \PhpZip\ZipOutputFile::openFromZipFile($zipFile);
|
|
|
|
|
|
|
+// with entry name
|
|
|
|
|
+$zipFile->addFile($filename, $entryName);
|
|
|
// or
|
|
// or
|
|
|
-$zipOutputFile = $zipFile->edit();
|
|
|
|
|
-```
|
|
|
|
|
-Add entry from file.
|
|
|
|
|
-```php
|
|
|
|
|
-$zipOutputFile->addFromFile($filename); // $entryName == basename($filename);
|
|
|
|
|
-$zipOutputFile->addFromFile($filename, $entryName);
|
|
|
|
|
-$zipOutputFile->addFromFile($filename, $entryName, ZipEntry::METHOD_DEFLATED);
|
|
|
|
|
-$zipOutputFile->addFromFile($filename, $entryName, ZipEntry::METHOD_STORED); // no compress
|
|
|
|
|
-$zipOutputFile->addFromFile($filename, null, ZipEntry::METHOD_BZIP2); // $entryName == basename($filename);
|
|
|
|
|
|
|
+$zipFile[$entryName] = new \SplFileInfo($filename);
|
|
|
|
|
+
|
|
|
|
|
+// with compression method
|
|
|
|
|
+$zipOFile->addFile($filename, $entryName, ZipFile::METHOD_DEFLATED); // Deflate compression
|
|
|
|
|
+$zipFile->addFile($filename, $entryName, ZipFile::METHOD_STORED); // No compression
|
|
|
|
|
+$zipFile->addFile($filename, null, ZipFile::METHOD_BZIP2); // BZIP2 compression
|
|
|
```
|
|
```
|
|
|
Add entry from string data.
|
|
Add entry from string data.
|
|
|
```php
|
|
```php
|
|
|
-$zipOutputFile->addFromString($entryName, $data);
|
|
|
|
|
-$zipOutputFile->addFromString($entryName, $data, ZipEntry::METHOD_DEFLATED);
|
|
|
|
|
-$zipOutputFile->addFromString($entryName, $data, ZipEntry::METHOD_STORED); // no compress
|
|
|
|
|
|
|
+$zipFile[$entryName] = $data;
|
|
|
|
|
+// or
|
|
|
|
|
+$zipFile->addFromString($entryName, $data);
|
|
|
|
|
+
|
|
|
|
|
+// with compression method
|
|
|
|
|
+$zipFile->addFromString($entryName, $data, ZipFile::METHOD_DEFLATED); // Deflate compression
|
|
|
|
|
+$zipFile->addFromString($entryName, $data, ZipFile::METHOD_STORED); // No compression
|
|
|
|
|
+$zipFile->addFromString($entryName, $data, ZipFile::METHOD_BZIP2); // BZIP2 compression
|
|
|
```
|
|
```
|
|
|
Add entry from stream.
|
|
Add entry from stream.
|
|
|
```php
|
|
```php
|
|
|
-$zipOutputFile->addFromStream($stream, $entryName);
|
|
|
|
|
-$zipOutputFile->addFromStream($stream, $entryName, ZipEntry::METHOD_DEFLATED);
|
|
|
|
|
-$zipOutputFile->addFromStream($stream, $entryName, ZipEntry::METHOD_STORED); // no compress
|
|
|
|
|
|
|
+// $stream = fopen(...);
|
|
|
|
|
+
|
|
|
|
|
+$zipFile->addFromStream($stream, $entryName);
|
|
|
|
|
+
|
|
|
|
|
+// with compression method
|
|
|
|
|
+$zipFile->addFromStream($stream, $entryName, ZipFile::METHOD_DEFLATED); Deflate compression
|
|
|
|
|
+$zipFile->addFromStream($stream, $entryName, ZipFile::METHOD_STORED); // No compression
|
|
|
|
|
+$zipFile->addFromStream($stream, $entryName, ZipFile::METHOD_BZIP2); // BZIP2 compression
|
|
|
```
|
|
```
|
|
|
Add empty dir
|
|
Add empty dir
|
|
|
```php
|
|
```php
|
|
|
-$zipOutputFile->addEmptyDir($dirName);
|
|
|
|
|
-```
|
|
|
|
|
-Add a directory **recursively** to the archive.
|
|
|
|
|
-```php
|
|
|
|
|
-$zipOutputFile->addDir($dirName);
|
|
|
|
|
|
|
+$zipFile->addEmptyDir($dirName);
|
|
|
// or
|
|
// or
|
|
|
-$zipOutputFile->addDir($dirName, true);
|
|
|
|
|
|
|
+$zipFile[$dirName] = null;
|
|
|
```
|
|
```
|
|
|
-Add a directory **not recursively** to the archive.
|
|
|
|
|
|
|
+Add all entries form string contents.
|
|
|
```php
|
|
```php
|
|
|
-$zipOutputFile->addDir($dirName, false);
|
|
|
|
|
|
|
+$mapData = [
|
|
|
|
|
+ 'file.txt' => 'file contents',
|
|
|
|
|
+ 'path/to/file.txt' => 'another file contents',
|
|
|
|
|
+ 'empty dir/' => null,
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+$zipFile->addAll($mapData);
|
|
|
```
|
|
```
|
|
|
-Add a directory to the archive by path `$moveToPath`
|
|
|
|
|
|
|
+Add a directory **not recursively** to the archive.
|
|
|
```php
|
|
```php
|
|
|
-$moveToPath = 'dir/subdir/';
|
|
|
|
|
-$zipOutputFile->addDir($dirName, $boolResursive, $moveToPath);
|
|
|
|
|
|
|
+$zipFile->addDir($dirName);
|
|
|
|
|
+
|
|
|
|
|
+// with entry path
|
|
|
|
|
+$localPath = "to/path/";
|
|
|
|
|
+$zipFile->addDir($dirName, $localPath);
|
|
|
|
|
+
|
|
|
|
|
+// with compression method for all files
|
|
|
|
|
+$zipFile->addDir($dirName, $localPath, ZipFile::METHOD_DEFLATED); Deflate compression
|
|
|
|
|
+$zipFile->addDir($dirName, $localPath, ZipFile::METHOD_STORED); // No compression
|
|
|
|
|
+$zipFile->addDir($dirName, $localPath, ZipFile::METHOD_BZIP2); // BZIP2 compression
|
|
|
|
|
+
|
|
|
```
|
|
```
|
|
|
Add a directory to the archive with ignoring files.
|
|
Add a directory to the archive with ignoring files.
|
|
|
```php
|
|
```php
|
|
@@ -263,7 +295,7 @@ $zipOutputFile->addDir($dirName, $boolResursive, $moveToPath, $ignoreFiles);
|
|
|
```
|
|
```
|
|
|
Add a directory and set compression method.
|
|
Add a directory and set compression method.
|
|
|
```php
|
|
```php
|
|
|
-$compressionMethod = ZipEntry::METHOD_DEFLATED;
|
|
|
|
|
|
|
+$compressionMethod = ZipFile::METHOD_DEFLATED;
|
|
|
$zipOutputFile->addDir($dirName, $boolRecursive, $moveToPath, $ignoreFiles, $compressionMethod);
|
|
$zipOutputFile->addDir($dirName, $boolRecursive, $moveToPath, $ignoreFiles, $compressionMethod);
|
|
|
```
|
|
```
|
|
|
Add a files **recursively** from [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) to the archive.
|
|
Add a files **recursively** from [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) to the archive.
|
|
@@ -283,7 +315,7 @@ $zipOutputFile->addFilesFromGlob($inputDir, $globPattern, $recursive = true, $mo
|
|
|
```
|
|
```
|
|
|
Add a files from [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) to the archive and set compression method.
|
|
Add a files from [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) to the archive and set compression method.
|
|
|
```php
|
|
```php
|
|
|
-$compressionMethod = ZipEntry::METHOD_DEFLATED;
|
|
|
|
|
|
|
+$compressionMethod = ZipFile::METHOD_DEFLATED;
|
|
|
$zipOutputFile->addFilesFromGlob($inputDir, $globPattern, $recursive, $moveToPath, $compressionMethod);
|
|
$zipOutputFile->addFilesFromGlob($inputDir, $globPattern, $recursive, $moveToPath, $compressionMethod);
|
|
|
```
|
|
```
|
|
|
Add a files **recursively** from [RegEx (Regular Expression) pattern](https://en.wikipedia.org/wiki/Regular_expression) to the archive.
|
|
Add a files **recursively** from [RegEx (Regular Expression) pattern](https://en.wikipedia.org/wiki/Regular_expression) to the archive.
|
|
@@ -303,7 +335,7 @@ $zipOutputFile->addFilesFromRegex($inputDir, $regexPattern, $recursive = true, $
|
|
|
```
|
|
```
|
|
|
Add a files from [RegEx (Regular Expression) pattern](https://en.wikipedia.org/wiki/Regular_expression) to the archive and set compression method.
|
|
Add a files from [RegEx (Regular Expression) pattern](https://en.wikipedia.org/wiki/Regular_expression) to the archive and set compression method.
|
|
|
```php
|
|
```php
|
|
|
-$compressionMethod = ZipEntry::METHOD_DEFLATED;
|
|
|
|
|
|
|
+$compressionMethod = ZipFile::METHOD_DEFLATED;
|
|
|
$zipOutputFile->addFilesFromRegex($inputDir, $regexPattern, $recursive, $moveToPath, $compressionMethod);
|
|
$zipOutputFile->addFilesFromRegex($inputDir, $regexPattern, $recursive, $moveToPath, $compressionMethod);
|
|
|
```
|
|
```
|
|
|
Rename entry name.
|
|
Rename entry name.
|
|
@@ -368,13 +400,13 @@ $zipOutputFile->setEntryComment($entryName, $entryComment);
|
|
|
```
|
|
```
|
|
|
Set compression method for zip entry.
|
|
Set compression method for zip entry.
|
|
|
```php
|
|
```php
|
|
|
-$compressionMethod = ZipEntry::METHOD_DEFLATED;
|
|
|
|
|
|
|
+$compressionMethod = ZipFile::METHOD_DEFLATED;
|
|
|
$zipOutputMethod->setCompressionMethod($entryName, $compressionMethod);
|
|
$zipOutputMethod->setCompressionMethod($entryName, $compressionMethod);
|
|
|
|
|
|
|
|
// Support compression methods:
|
|
// Support compression methods:
|
|
|
-// ZipEntry::METHOD_STORED - no compression
|
|
|
|
|
-// ZipEntry::METHOD_DEFLATED - deflate compression
|
|
|
|
|
-// ZipEntry::METHOD_BZIP2 - bzip2 compression (need bz2 extension)
|
|
|
|
|
|
|
+// ZipFile::METHOD_STORED - no compression
|
|
|
|
|
+// ZipFile::METHOD_DEFLATED - deflate compression
|
|
|
|
|
+// ZipFile::METHOD_BZIP2 - bzip2 compression (need bz2 extension)
|
|
|
```
|
|
```
|
|
|
Set a password for all previously added entries.
|
|
Set a password for all previously added entries.
|
|
|
```php
|
|
```php
|
|
@@ -382,12 +414,12 @@ $zipOutputFile->setPassword($password);
|
|
|
```
|
|
```
|
|
|
Set a password and encryption method for all previously added entries.
|
|
Set a password and encryption method for all previously added entries.
|
|
|
```php
|
|
```php
|
|
|
-$encryptionMethod = ZipEntry::ENCRYPTION_METHOD_WINZIP_AES; // default value
|
|
|
|
|
|
|
+$encryptionMethod = ZipFile::ENCRYPTION_METHOD_WINZIP_AES; // default value
|
|
|
$zipOutputFile->setPassword($password, $encryptionMethod);
|
|
$zipOutputFile->setPassword($password, $encryptionMethod);
|
|
|
|
|
|
|
|
// Support encryption methods:
|
|
// Support encryption methods:
|
|
|
-// ZipEntry::ENCRYPTION_METHOD_TRADITIONAL - Traditional PKWARE Encryption
|
|
|
|
|
-// ZipEntry::ENCRYPTION_METHOD_WINZIP_AES - WinZip AES Encryption
|
|
|
|
|
|
|
+// ZipFile::ENCRYPTION_METHOD_TRADITIONAL - Traditional PKWARE Encryption
|
|
|
|
|
+// ZipFile::ENCRYPTION_METHOD_WINZIP_AES - WinZip AES Encryption
|
|
|
```
|
|
```
|
|
|
Set a password for a concrete entry.
|
|
Set a password for a concrete entry.
|
|
|
```php
|
|
```php
|
|
@@ -398,8 +430,8 @@ Set a password and encryption method for a concrete entry.
|
|
|
$zipOutputFile->setEntryPassword($entryName, $password, $encryptionMethod);
|
|
$zipOutputFile->setEntryPassword($entryName, $password, $encryptionMethod);
|
|
|
|
|
|
|
|
// Support encryption methods:
|
|
// Support encryption methods:
|
|
|
-// ZipEntry::ENCRYPTION_METHOD_TRADITIONAL - Traditional PKWARE Encryption
|
|
|
|
|
-// ZipEntry::ENCRYPTION_METHOD_WINZIP_AES - WinZip AES Encryption (default value)
|
|
|
|
|
|
|
+// ZipFile::ENCRYPTION_METHOD_TRADITIONAL - Traditional PKWARE Encryption
|
|
|
|
|
+// ZipFile::ENCRYPTION_METHOD_WINZIP_AES - WinZip AES Encryption (default value)
|
|
|
```
|
|
```
|
|
|
Remove password from all entries.
|
|
Remove password from all entries.
|
|
|
```php
|
|
```php
|