ソースを参照

update README

wapplay 7 年 前
コミット
062762ed09
2 ファイル変更46 行追加30 行削除
  1. 23 15
      README.RU.md
  2. 23 15
      README.md

+ 23 - 15
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/`.
 

+ 23 - 15
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