phar_copy.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Phar: copy() zip-based
  3. --EXTENSIONS--
  4. phar
  5. --INI--
  6. phar.readonly=0
  7. phar.require_hash=1
  8. --FILE--
  9. <?php
  10. $fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
  11. $fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '2.phar.php';
  12. $pname = 'phar://'.$fname;
  13. $iname = '/file.txt';
  14. $ename = '/error/..';
  15. $p = new Phar($fname);
  16. try
  17. {
  18. $p['a'] = 'hi';
  19. $p->startBuffering();
  20. $p->copy('a', 'b');
  21. echo file_get_contents($p['b']->getPathName());
  22. $p->copy('b', 'c');
  23. $p->stopBuffering();
  24. echo file_get_contents($p['c']->getPathName());
  25. copy($fname, $fname2);
  26. var_dump($p->isFileFormat(Phar::ZIP));
  27. $p->copy('a', $ename);
  28. }
  29. catch(Exception $e)
  30. {
  31. echo $e->getMessage() . "\n";
  32. }
  33. ini_set('phar.readonly',1);
  34. $p2 = new Phar($fname2);
  35. var_dump($p2->isFileFormat(Phar::ZIP));
  36. echo "\n";
  37. echo 'a: ' , file_get_contents($p2['a']->getPathName());
  38. echo 'b: ' ,file_get_contents($p2['b']->getPathName());
  39. echo 'c: ' ,file_get_contents($p2['c']->getPathName());
  40. ?>
  41. ===DONE===
  42. --CLEAN--
  43. <?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
  44. <?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
  45. --EXPECTF--
  46. hihibool(true)
  47. file "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s
  48. bool(true)
  49. a: hib: hic: hi===DONE===