aboutsummaryrefslogtreecommitdiff
path: root/examples/06-file_writer.php
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-02 13:25:53 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:39 -0400
commitc6485275e8ccf50ae6adf6a7f5ed7519e8145406 (patch)
tree9327883785f350d3abb8dd3320f49e0fc28e874e /examples/06-file_writer.php
parentb520b6459d7b5a3dfb31c1b3febf02887bb07505 (diff)
downloadzipstream-php-c6485275e8ccf50ae6adf6a7f5ed7519e8145406.tar.bz2
zipstream-php-c6485275e8ccf50ae6adf6a7f5ed7519e8145406.zip
refactor FileWriter, add FileWriter example
Diffstat (limited to 'examples/06-file_writer.php')
-rw-r--r--examples/06-file_writer.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/06-file_writer.php b/examples/06-file_writer.php
new file mode 100644
index 0000000..7a98910
--- /dev/null
+++ b/examples/06-file_writer.php
@@ -0,0 +1,22 @@
+<?php
+declare(strict_types = 1);
+
+require_once __DIR__ . '/../src/ZipStream.php';
+
+# import zipstream classes
+use Pablotron\ZipStream\ZipStream;
+use Pablotron\ZipStream\FileWriter;
+
+# save as "example.zip" in examples directory
+$zip_path = __DIR__ . '/example.zip';
+
+$zip = new ZipStream($zip_path, [
+ 'output' => new FileWriter(),
+]);
+
+# add a file named "hello.txt" to output archive, containing
+# the string "hello world!"
+$zip->add_file('hello.txt', 'hello world!');
+
+# finalize archive
+$zip->close();