aboutsummaryrefslogtreecommitdiff
path: root/examples/13-add_file_times.php
diff options
context:
space:
mode:
Diffstat (limited to 'examples/13-add_file_times.php')
-rw-r--r--examples/13-add_file_times.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/13-add_file_times.php b/examples/13-add_file_times.php
new file mode 100644
index 0000000..bf226b3
--- /dev/null
+++ b/examples/13-add_file_times.php
@@ -0,0 +1,32 @@
+<?php
+declare(strict_types = 1);
+
+require_once __DIR__ . '/../src/ZipStream.php';
+
+# import zipstream classes
+use Pablotron\ZipStream\ZipStream;
+use Pablotron\ZipStream\FileWriter;
+
+# output zip path
+$zip_path = __DIR__ . '/example-13.zip';
+
+# output options
+$zip_args = [
+ 'output' => new FileWriter(),
+];
+
+# create archive in this directory with a comment
+ZipStream::send($zip_path, function(ZipStream &$zip) {
+ # get current time
+ $time = time();
+
+ # add "hello.txt" to output with a time of 2 hours ago
+ $zip->add_file('hello.txt', 'hello world!', [
+ 'time' => $time - (2 * 3600),
+ ]);
+
+ # add "hola.txt" to output with a time of 2 hours in the future
+ $zip->add_file('hola.txt', 'hola!!', [
+ 'time' => $time + (2 * 3600),
+ ]);
+}, $zip_args);