diff options
author | SVN Migration <svn@php.net> | 2006-07-24 16:58:59 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2006-07-24 16:58:59 +0000 |
commit | 664d102aa65af165bf25163b220424e67241369c (patch) | |
tree | b646eb8123fe74905c50450b3971826383c41b75 /ext/zip/examples | |
parent | 467e129ce5aae75bc23ad69f7c4f66985382bd5a (diff) | |
download | php-git-664d102aa65af165bf25163b220424e67241369c.tar.gz |
This commit was manufactured by cvs2svn to create branch 'PHP_5_2'.
Diffstat (limited to 'ext/zip/examples')
-rw-r--r-- | ext/zip/examples/comment.php | 6 | ||||
-rw-r--r-- | ext/zip/examples/create.php | 23 | ||||
-rw-r--r-- | ext/zip/examples/dir.php | 21 | ||||
-rw-r--r-- | ext/zip/examples/extract.php | 28 | ||||
-rw-r--r-- | ext/zip/examples/extractAll.php | 24 | ||||
-rw-r--r-- | ext/zip/examples/fopen.php | 35 | ||||
-rw-r--r-- | ext/zip/examples/get_set_comments.php | 38 | ||||
-rw-r--r-- | ext/zip/examples/im.php | 11 | ||||
-rw-r--r-- | ext/zip/examples/odt.php | 20 | ||||
-rw-r--r-- | ext/zip/examples/oldapi.php | 17 | ||||
-rw-r--r-- | ext/zip/examples/test.odt | bin | 0 -> 6162 bytes | |||
-rw-r--r-- | ext/zip/examples/test.zip | bin | 0 -> 541 bytes | |||
-rw-r--r-- | ext/zip/examples/test1.zip | bin | 0 -> 681 bytes | |||
-rw-r--r-- | ext/zip/examples/test_im.zip | bin | 0 -> 1086 bytes | |||
-rw-r--r-- | ext/zip/examples/test_with_comment.zip | bin | 0 -> 560 bytes | |||
-rw-r--r-- | ext/zip/examples/too.php | 2 |
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 0000000000..90b37d3795 --- /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 0000000000..a41c8e6d0b --- /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 0000000000..c362a72ba3 --- /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 0000000000..5276b0dca5 --- /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 0000000000..d318a453df --- /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 0000000000..32357f3c08 --- /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 0000000000..5bd302e6da --- /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 0000000000..3721434054 --- /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 0000000000..c829f12343 --- /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 0000000000..2f17f43ebd --- /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 Binary files differnew file mode 100644 index 0000000000..6a816ad749 --- /dev/null +++ b/ext/zip/examples/test.odt diff --git a/ext/zip/examples/test.zip b/ext/zip/examples/test.zip Binary files differnew file mode 100644 index 0000000000..6b98694803 --- /dev/null +++ b/ext/zip/examples/test.zip diff --git a/ext/zip/examples/test1.zip b/ext/zip/examples/test1.zip Binary files differnew file mode 100644 index 0000000000..a4deb13c6b --- /dev/null +++ b/ext/zip/examples/test1.zip diff --git a/ext/zip/examples/test_im.zip b/ext/zip/examples/test_im.zip Binary files differnew file mode 100644 index 0000000000..6385ee9252 --- /dev/null +++ b/ext/zip/examples/test_im.zip diff --git a/ext/zip/examples/test_with_comment.zip b/ext/zip/examples/test_with_comment.zip Binary files differnew file mode 100644 index 0000000000..cc65375fb5 --- /dev/null +++ b/ext/zip/examples/test_with_comment.zip diff --git a/ext/zip/examples/too.php b/ext/zip/examples/too.php new file mode 100644 index 0000000000..6d2100811e --- /dev/null +++ b/ext/zip/examples/too.php @@ -0,0 +1,2 @@ +<?php +echo "too"; |