summaryrefslogtreecommitdiff
path: root/ext/zip/examples
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zip/examples')
-rw-r--r--ext/zip/examples/comment.php6
-rw-r--r--ext/zip/examples/create.php23
-rw-r--r--ext/zip/examples/dir.php21
-rw-r--r--ext/zip/examples/extract.php28
-rw-r--r--ext/zip/examples/extractAll.php24
-rw-r--r--ext/zip/examples/fopen.php35
-rw-r--r--ext/zip/examples/get_set_comments.php38
-rw-r--r--ext/zip/examples/im.php11
-rw-r--r--ext/zip/examples/odt.php20
-rw-r--r--ext/zip/examples/oldapi.php17
-rw-r--r--ext/zip/examples/test.odtbin0 -> 6162 bytes
-rw-r--r--ext/zip/examples/test.zipbin0 -> 553 bytes
-rw-r--r--ext/zip/examples/test1.zipbin0 -> 681 bytes
-rw-r--r--ext/zip/examples/test_im.zipbin0 -> 1086 bytes
-rw-r--r--ext/zip/examples/test_with_comment.zipbin0 -> 560 bytes
-rw-r--r--ext/zip/examples/too.php2
16 files changed, 225 insertions, 0 deletions
diff --git a/ext/zip/examples/comment.php b/ext/zip/examples/comment.php
new file mode 100644
index 0000000..90b37d3
--- /dev/null
+++ b/ext/zip/examples/comment.php
@@ -0,0 +1,6 @@
+<?php
+$z = new ZipArchive;
+$z->open('test_with_comment.zip');
+// Add "Foo Comment" as comment for the foo entry
+$z->setCommentName('foo', 'Too Comment ' . time());
+$z->close();
diff --git a/ext/zip/examples/create.php b/ext/zip/examples/create.php
new file mode 100644
index 0000000..a41c8e6
--- /dev/null
+++ b/ext/zip/examples/create.php
@@ -0,0 +1,23 @@
+<?php
+error_reporting(E_ALL);
+if (!extension_loaded('zip')) {
+ dl('zip.so');
+}
+$thisdir = dirname(__FILE__);
+unlink("./test112.zip");
+$zip = new ZipArchive();
+$filename = "./test112.zip";
+
+if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
+ exit("cannot open <$filename>\n");
+} else {
+ echo "file <$filename> OK\n";
+}
+
+$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
+$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
+$zip->addFile($thisdir . "/too.php","/testfromfile.php");
+echo "numfiles: " . $zip->numFiles . "\n";
+echo "status:" . $zip->status . "\n";
+$zip->close();
+unset($zip);
diff --git a/ext/zip/examples/dir.php b/ext/zip/examples/dir.php
new file mode 100644
index 0000000..c362a72
--- /dev/null
+++ b/ext/zip/examples/dir.php
@@ -0,0 +1,21 @@
+<?php
+if (!extension_loaded('zip')) {
+ dl('zip.so');
+}
+
+$za = new ZipArchive();
+
+$za->open('test_with_comment.zip');
+print_r($za);
+var_dump($za);
+echo "numFiles: " . $za->numFiles . "\n";
+echo "status: " . $za->status . "\n";
+echo "statusSys: " . $za->statusSys . "\n";
+echo "filename: " . $za->filename . "\n";
+echo "comment: " . $za->comment . "\n";
+
+for ($i=0; $i<$za->numFiles;$i++) {
+ echo "index: $i\n";
+ print_r($za->statIndex($i));
+}
+echo "numFile:" . $za->numFiles . "\n";
diff --git a/ext/zip/examples/extract.php b/ext/zip/examples/extract.php
new file mode 100644
index 0000000..5276b0d
--- /dev/null
+++ b/ext/zip/examples/extract.php
@@ -0,0 +1,28 @@
+<?php
+if (!extension_loaded('zip')) {
+ dl('zip.so');
+}
+
+$zip = new ZipArchive();
+
+echo $zip->filename . "\n";
+$zip->open("test.zip");
+/*
+$zip->addFile("./modules/");
+$zip->addFile("./testempty");
+*/
+echo $zip->status . "\n";
+echo $zip->statusSys . "\n";
+
+echo $zip->numFiles . "\n";
+echo $zip->filename . "\n";
+var_dump($zip);
+$files = array('test', 'testdir/test2');
+if (!$zip->extractTo("./testext/path/to", $files)) {
+ echo "error!\n";
+ echo $zip->status . "\n";
+ echo $zip->statusSys . "\n";
+
+}
+
+$zip->close();
diff --git a/ext/zip/examples/extractAll.php b/ext/zip/examples/extractAll.php
new file mode 100644
index 0000000..d318a45
--- /dev/null
+++ b/ext/zip/examples/extractAll.php
@@ -0,0 +1,24 @@
+<?php
+$zip = new ZipArchive();
+
+echo $zip->filename . "\n";
+$zip->open("test.zip");
+/*
+$zip->addFile("./modules/");
+$zip->addFile("./testempty");
+*/
+echo $zip->status . "\n";
+echo $zip->statusSys . "\n";
+
+echo $zip->numFiles . "\n";
+echo $zip->filename . "\n";
+var_dump($zip);
+$files = array('test', 'testdir/test2');
+if (!$zip->extractTo("./testext/path/to")) {
+ echo "error!\n";
+ echo $zip->status . "\n";
+ echo $zip->statusSys . "\n";
+
+}
+
+$zip->close();
diff --git a/ext/zip/examples/fopen.php b/ext/zip/examples/fopen.php
new file mode 100644
index 0000000..32357f3
--- /dev/null
+++ b/ext/zip/examples/fopen.php
@@ -0,0 +1,35 @@
+<?php
+if (!extension_loaded('zip')) {
+ dl('zip.so');
+}
+
+
+$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
+if (!$fp) {
+ exit("cannot open\n");
+}
+while (!feof($fp)) {
+ $contents .= fread($fp, 2);
+ echo "$contents\n";
+}
+
+fclose($fp);
+echo "done.\n";
+
+
+$content = '';
+$z = new ZipArchive();
+$z->open(dirname(__FILE__) . '/test.zip');
+$fp = $z->getStream('test');
+
+var_dump($fp);
+if(!$fp) exit("\n");
+while (!feof($fp)) {
+ $contents .= fread($fp, 2);
+}
+
+fclose($fp);
+file_put_contents('t',$contents);
+echo "done.\n";
+
+
diff --git a/ext/zip/examples/get_set_comments.php b/ext/zip/examples/get_set_comments.php
new file mode 100644
index 0000000..5bd302e
--- /dev/null
+++ b/ext/zip/examples/get_set_comments.php
@@ -0,0 +1,38 @@
+<?php
+error_reporting(E_ALL|E_STRICT);
+
+copy('test_with_comment.zip', 't.zip');
+$z = new ZipArchive;
+$z->open('t.zip');
+
+print_r($z);
+
+for ($i=0; $i<$z->numFiles; $i++) {
+ echo "index: $i\n";
+ print_r($z->getCommentIndex($i));
+ echo "\n\n";
+}
+echo "foobar/ " . $z->getCommentName('foobar/') . "\n";
+
+echo "Archive comment: " . $z->getArchiveComment() . "\n";
+
+
+$z->setCommentIndex(1, 'new comment idx 1');
+$z->setCommentName('foobar/', 'new comment foobar/');
+
+$z->setArchiveComment( 'new archive comment');
+
+for ($i=0; $i<$z->numFiles; $i++) {
+ echo "index: $i\n";
+ print_r($z->getCommentIndex($i));
+ echo "\n\n";
+}
+
+echo $z->getCommentName('foobar/') . "\n";
+
+// Get the original comment
+echo $z->getCommentName('foobar/', ZIPARCHIVE::FL_UNCHANGED) . "\n";
+
+echo "Archive comment: " . $z->getArchiveComment() . "\n";
+echo "Archive comment (original): " . $z->getArchiveComment(ZIPARCHIVE::FL_UNCHANGED) . "\n";
+
diff --git a/ext/zip/examples/im.php b/ext/zip/examples/im.php
new file mode 100644
index 0000000..3721434
--- /dev/null
+++ b/ext/zip/examples/im.php
@@ -0,0 +1,11 @@
+<?php
+/* $Id$ */
+$im = imagecreatefromgif('zip://' . dirname(__FILE__) . '/test_im.zip#pear_item.gif');
+imagepng($im, 'a.png');
+
+$z = new ZipArchive();
+$z->open(dirname(__FILE__) . '/test_im.zip');
+$im_string = $z->getFromName("pear_item.gif");
+$im = imagecreatefromstring($im_string);
+imagepng($im, 'b.png');
+
diff --git a/ext/zip/examples/odt.php b/ext/zip/examples/odt.php
new file mode 100644
index 0000000..c829f12
--- /dev/null
+++ b/ext/zip/examples/odt.php
@@ -0,0 +1,20 @@
+<?php
+/* $Id$ */
+$reader = new XMLReader();
+
+$reader->open('zip://' . dirname(__FILE__) . '/test.odt#meta.xml');
+$odt_meta = array();
+while ($reader->read()) {
+ if ($reader->nodeType == XMLREADER::ELEMENT) {
+ $elm = $reader->name;
+ } else {
+ if ($reader->nodeType == XMLREADER::END_ELEMENT && $reader->name == 'office:meta') {
+ break;
+ }
+ if (!trim($reader->value)) {
+ continue;
+ }
+ $odt_meta[$elm] = $reader->value;
+ }
+}
+print_r($odt_meta);
diff --git a/ext/zip/examples/oldapi.php b/ext/zip/examples/oldapi.php
new file mode 100644
index 0000000..2f17f43
--- /dev/null
+++ b/ext/zip/examples/oldapi.php
@@ -0,0 +1,17 @@
+<?php
+
+$zip = zip_open('examples/test1.zip');
+var_dump($zip);
+
+if ($zip) {
+ $i = 0;
+ while ($zip_entry = zip_read($zip)) {
+ var_dump($zip_entry);
+ $txt = zip_entry_read($zip_entry, 10);
+ echo $i . ": " . $txt . "size: " . zip_entry_filesize($zip_entry) .
+ "comp_method: " . zip_entry_compressionmethod($zip_entry) .
+ "\n";
+ $i++;
+ }
+ var_dump($zip_entry);
+}
diff --git a/ext/zip/examples/test.odt b/ext/zip/examples/test.odt
new file mode 100644
index 0000000..6a816ad
--- /dev/null
+++ b/ext/zip/examples/test.odt
Binary files differ
diff --git a/ext/zip/examples/test.zip b/ext/zip/examples/test.zip
new file mode 100644
index 0000000..a6a2e62
--- /dev/null
+++ b/ext/zip/examples/test.zip
Binary files differ
diff --git a/ext/zip/examples/test1.zip b/ext/zip/examples/test1.zip
new file mode 100644
index 0000000..a4deb13
--- /dev/null
+++ b/ext/zip/examples/test1.zip
Binary files differ
diff --git a/ext/zip/examples/test_im.zip b/ext/zip/examples/test_im.zip
new file mode 100644
index 0000000..6385ee9
--- /dev/null
+++ b/ext/zip/examples/test_im.zip
Binary files differ
diff --git a/ext/zip/examples/test_with_comment.zip b/ext/zip/examples/test_with_comment.zip
new file mode 100644
index 0000000..cc65375
--- /dev/null
+++ b/ext/zip/examples/test_with_comment.zip
Binary files differ
diff --git a/ext/zip/examples/too.php b/ext/zip/examples/too.php
new file mode 100644
index 0000000..6d21008
--- /dev/null
+++ b/ext/zip/examples/too.php
@@ -0,0 +1,2 @@
+<?php
+echo "too";