Advertisement
freephile

Exception in PharData

Mar 1st, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. /**
  2.  * Trying to add tgz handling via the Phar extension which is built-in to PHP
  3.  * However, we can't get a file listing of a zip file using PharData()
  4.  * This zip archive /IS/ properly handled by both
  5.  * Directory Iterator itself, or the zip_open() and related methods.
  6.  */
  7.  
  8.  
  9. # first make a zip archive by using wget to grab a creative commons blog post
  10. wget --page-requisites --convert-links --no-host-directories --no-directories --directory-prefix=cc.org --adjust-extension http://creativecommons.org/weblog/entry/43316
  11. zip --junk-paths cc.zip ./cc.org/*
  12. rm -rf ./cc.org
  13.  
  14. # you should now have a zip file named 'cc.zip' with the following contents
  15. 43316.html
  16. Peters_projection_blank.png
  17. arrow-next.png
  18. arrow-prev.png
  19. cc.cc-27x30.png
  20. cc.logo-126x30.png
  21. cforms.js
  22. creativecommons.css
  23. facebook.png
  24. identica.png
  25. modernizr-2.0.6.min.js
  26. pagenavi-css.css?ver=2.70.css
  27. pagination.png
  28. plugins.js
  29. robots.txt
  30. script.js
  31. search-glass.png
  32. style.css
  33. twitter.png
  34. websitebanner2014_teal.png
  35. widget.css?ver=4.1.1.css
  36.  
  37.  
  38.  
  39. <?php
  40.  
  41. class Foo {
  42.    
  43.     function readArchive ($archiveFile, $flags, $alias, $format) {
  44.       $reader = new PharData($archiveFile, $flags, $alias, $format);
  45.       foreach ($reader as $file) {
  46.           $filename = $file->getFilename();
  47.           echo "$filename\n";
  48.       }
  49.     }
  50. }
  51.  
  52.  
  53. $flags=null;
  54. $alias=null;
  55. $format = Phar::ZIP;
  56. $format=null;
  57. $myArchive = realpath( __DIR__ . '/cc.zip');
  58.  
  59. $reader = new Foo;
  60. $reader->readArchive($myArchive, $flags, $alias, $format);
  61.  
  62. // produces error
  63. // PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Cannot access phar file entry '/pagenavi-css.css?ver=2.70.css' in archive
  64.  
  65.  
  66. $it = new FilesystemIterator("phar://$myArchive");
  67. foreach ($it as $fileinfo) {
  68.     echo $fileinfo->getFilename() . "\n";
  69. }
  70.  
  71. // works as expected, producing a complete list of the zip contents
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement