aboutsummaryrefslogtreecommitdiff
path: root/examples/07-stream_writer.php
blob: d94e7acb1a2d0dfd9ec804b98eec77ce17d44ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
declare(strict_types = 1);

require_once __DIR__ . '/../src/ZipStream.php';

# import zipstream classes
use Pablotron\ZipStream\ZipStream;
use Pablotron\ZipStream\StreamWriter;

# save as "example.zip" in examples directory
$zip_path = __DIR__ . '/example.zip';

# open output stream
$out_stream = fopen($zip_path, 'wb');

# create zipstream
# NOTE: output archive name is ignored for StreamWriter
$zip = new ZipStream('', [
  'output' => new StreamWriter($out_stream),
]);

# 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();

# close output stream
fclose($out_stream);