xref: /PHP-7.0/ext/zip/examples/create.php (revision b734bf4b)
1<?php
2error_reporting(E_ALL);
3if (!extension_loaded('zip')) {
4    dl('zip.so');
5}
6$thisdir = dirname(__FILE__);
7unlink("./test112.zip");
8$zip = new ZipArchive();
9$filename = "./test112.zip";
10
11if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
12	exit("cannot open <$filename>\n");
13} else {
14	echo "file <$filename> OK\n";
15}
16
17$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
18$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
19$zip->addFile($thisdir . "/too.php","/testfromfile.php");
20echo "numfiles: " . $zip->numFiles . "\n";
21echo "status:" . $zip->status . "\n";
22$zip->close();
23unset($zip);
24