1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-07-18 22:51:11 +02:00

update README

This commit is contained in:
wapplay
2018-10-10 07:41:19 +03:00
parent e1866215a6
commit 062762ed09
2 changed files with 46 additions and 30 deletions

View File

@@ -78,21 +78,29 @@
```php ```php
// создание нового архива // создание нового архива
$zipFile = new \PhpZip\ZipFile(); $zipFile = new \PhpZip\ZipFile();
$zipFile try{
->addFromString("zip/entry/filename", "Is file content") // добавить запись из строки $zipFile
->addFile("/path/to/file", "data/tofile") // добавить запись из файла ->addFromString("zip/entry/filename", "Is file content") // добавить запись из строки
->addDir(__DIR__, "to/path/") // добавить файлы из директории ->addFile("/path/to/file", "data/tofile") // добавить запись из файла
->saveAsFile($outputFilename) // сохранить архив в файл ->addDir(__DIR__, "to/path/") // добавить файлы из директории
->close(); // закрыть архив ->saveAsFile($outputFilename) // сохранить архив в файл
->close(); // закрыть архив
// открытие архива, извлечение файлов, удаление файлов, добавление файлов, установка пароля и вывод архива в браузер.
$zipFile // открытие архива, извлечение файлов, удаление файлов, добавление файлов, установка пароля и вывод архива в браузер.
->openFile($outputFilename) // открыть архив из файла $zipFile
->extractTo($outputDirExtract) // извлечь файлы в заданную директорию ->openFile($outputFilename) // открыть архив из файла
->deleteFromRegex('~^\.~') // удалить все скрытые (Unix) файлы ->extractTo($outputDirExtract) // извлечь файлы в заданную директорию
->addFromString('dir/file.txt', 'Test file') // добавить новую запись из строки ->deleteFromRegex('~^\.~') // удалить все скрытые (Unix) файлы
->setPassword('password') // установить пароль на все записи ->addFromString('dir/file.txt', 'Test file') // добавить новую запись из строки
->outputAsAttachment('library.jar'); // вывести в браузер без сохранения в файл ->setPassword('password') // установить пароль на все записи
->outputAsAttachment('library.jar'); // вывести в браузер без сохранения в файл
}
catch(\PhpZip\Exception\ZipException $e){
// обработка исключения
}
finally{
$zip->close();
}
``` ```
Другие примеры можно посмотреть в папке `tests/`. Другие примеры можно посмотреть в папке `tests/`.

View File

@@ -78,21 +78,29 @@ Latest stable version: [![Latest Stable Version](https://poser.pugx.org/nelexa/z
```php ```php
// create new archive // create new archive
$zipFile = new \PhpZip\ZipFile(); $zipFile = new \PhpZip\ZipFile();
$zipFile try{
->addFromString("zip/entry/filename", "Is file content") // add an entry from the string $zipFile
->addFile("/path/to/file", "data/tofile") // add an entry from the file ->addFromString("zip/entry/filename", "Is file content") // add an entry from the string
->addDir(__DIR__, "to/path/") // add files from the directory ->addFile("/path/to/file", "data/tofile") // add an entry from the file
->saveAsFile($outputFilename) // save the archive to a file ->addDir(__DIR__, "to/path/") // add files from the directory
->close(); // close archive ->saveAsFile($outputFilename) // save the archive to a file
->close(); // close archive
// open archive, extract, add files, set password and output to browser.
$zipFile // open archive, extract, add files, set password and output to browser.
->openFile($outputFilename) // open archive from file $zipFile
->extractTo($outputDirExtract) // extract files to the specified directory ->openFile($outputFilename) // open archive from file
->deleteFromRegex('~^\.~') // delete all hidden (Unix) files ->extractTo($outputDirExtract) // extract files to the specified directory
->addFromString('dir/file.txt', 'Test file') // add a new entry from the string ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
->setPassword('password') // set password for all entries ->addFromString('dir/file.txt', 'Test file') // add a new entry from the string
->outputAsAttachment('library.jar'); // output to the browser without saving to a file ->setPassword('password') // set password for all entries
->outputAsAttachment('library.jar'); // output to the browser without saving to a file
}
catch(\PhpZip\Exception\ZipException $e){
// handle exception
}
finally{
$zip->close();
}
``` ```
Other examples can be found in the `tests/` folder Other examples can be found in the `tests/` folder