Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Trying to add tgz handling via the Phar extension which is built-in to PHP
- * However, we can't get a file listing of a zip file using PharData()
- * This zip archive /IS/ properly handled by both
- * Directory Iterator itself, or the zip_open() and related methods.
- */
- # first make a zip archive by using wget to grab a creative commons blog post
- wget --page-requisites --convert-links --no-host-directories --no-directories --directory-prefix=cc.org --adjust-extension http://creativecommons.org/weblog/entry/43316
- zip --junk-paths cc.zip ./cc.org/*
- rm -rf ./cc.org
- # you should now have a zip file named 'cc.zip' with the following contents
- 43316.html
- Peters_projection_blank.png
- arrow-next.png
- arrow-prev.png
- cc.cc-27x30.png
- cc.logo-126x30.png
- cforms.js
- creativecommons.css
- facebook.png
- identica.png
- modernizr-2.0.6.min.js
- pagenavi-css.css?ver=2.70.css
- pagination.png
- plugins.js
- robots.txt
- script.js
- search-glass.png
- style.css
- twitter.png
- websitebanner2014_teal.png
- widget.css?ver=4.1.1.css
- <?php
- class Foo {
- function readArchive ($archiveFile, $flags, $alias, $format) {
- $reader = new PharData($archiveFile, $flags, $alias, $format);
- foreach ($reader as $file) {
- $filename = $file->getFilename();
- echo "$filename\n";
- }
- }
- }
- $flags=null;
- $alias=null;
- $format = Phar::ZIP;
- $format=null;
- $myArchive = realpath( __DIR__ . '/cc.zip');
- $reader = new Foo;
- $reader->readArchive($myArchive, $flags, $alias, $format);
- // produces error
- // PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot access phar file entry '/pagenavi-css.css?ver=2.70.css' in archive
- $it = new FilesystemIterator("phar://$myArchive");
- foreach ($it as $fileinfo) {
- echo $fileinfo->getFilename() . "\n";
- }
- // works as expected, producing a complete list of the zip contents
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement