From 062762ed09c9abf806d8f84a252de938ab0a9b97 Mon Sep 17 00:00:00 2001 From: wapplay Date: Wed, 10 Oct 2018 07:41:19 +0300 Subject: [PATCH] update README --- README.RU.md | 38 +++++++++++++++++++++++--------------- README.md | 38 +++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/README.RU.md b/README.RU.md index d110d4f..9af353e 100644 --- a/README.RU.md +++ b/README.RU.md @@ -78,21 +78,29 @@ ```php // создание нового архива $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 - ->openFile($outputFilename) // открыть архив из файла - ->extractTo($outputDirExtract) // извлечь файлы в заданную директорию - ->deleteFromRegex('~^\.~') // удалить все скрытые (Unix) файлы - ->addFromString('dir/file.txt', 'Test file') // добавить новую запись из строки - ->setPassword('password') // установить пароль на все записи - ->outputAsAttachment('library.jar'); // вывести в браузер без сохранения в файл +try{ + $zipFile + ->addFromString("zip/entry/filename", "Is file content") // добавить запись из строки + ->addFile("/path/to/file", "data/tofile") // добавить запись из файла + ->addDir(__DIR__, "to/path/") // добавить файлы из директории + ->saveAsFile($outputFilename) // сохранить архив в файл + ->close(); // закрыть архив + + // открытие архива, извлечение файлов, удаление файлов, добавление файлов, установка пароля и вывод архива в браузер. + $zipFile + ->openFile($outputFilename) // открыть архив из файла + ->extractTo($outputDirExtract) // извлечь файлы в заданную директорию + ->deleteFromRegex('~^\.~') // удалить все скрытые (Unix) файлы + ->addFromString('dir/file.txt', 'Test file') // добавить новую запись из строки + ->setPassword('password') // установить пароль на все записи + ->outputAsAttachment('library.jar'); // вывести в браузер без сохранения в файл +} +catch(\PhpZip\Exception\ZipException $e){ + // обработка исключения +} +finally{ + $zip->close(); +} ``` Другие примеры можно посмотреть в папке `tests/`. diff --git a/README.md b/README.md index afacf1c..a0aa7cb 100644 --- a/README.md +++ b/README.md @@ -78,21 +78,29 @@ Latest stable version: [![Latest Stable Version](https://poser.pugx.org/nelexa/z ```php // create new archive $zipFile = new \PhpZip\ZipFile(); -$zipFile - ->addFromString("zip/entry/filename", "Is file content") // add an entry from the string - ->addFile("/path/to/file", "data/tofile") // add an entry from the file - ->addDir(__DIR__, "to/path/") // add files from the directory - ->saveAsFile($outputFilename) // save the archive to a file - ->close(); // close archive - -// open archive, extract, add files, set password and output to browser. -$zipFile - ->openFile($outputFilename) // open archive from file - ->extractTo($outputDirExtract) // extract files to the specified directory - ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files - ->addFromString('dir/file.txt', 'Test file') // add a new entry from the string - ->setPassword('password') // set password for all entries - ->outputAsAttachment('library.jar'); // output to the browser without saving to a file +try{ + $zipFile + ->addFromString("zip/entry/filename", "Is file content") // add an entry from the string + ->addFile("/path/to/file", "data/tofile") // add an entry from the file + ->addDir(__DIR__, "to/path/") // add files from the directory + ->saveAsFile($outputFilename) // save the archive to a file + ->close(); // close archive + + // open archive, extract, add files, set password and output to browser. + $zipFile + ->openFile($outputFilename) // open archive from file + ->extractTo($outputDirExtract) // extract files to the specified directory + ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files + ->addFromString('dir/file.txt', 'Test file') // add a new entry from the string + ->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