oo_extract.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. --TEST--
  2. extractTo
  3. --EXTENSIONS--
  4. zip
  5. --FILE--
  6. <?php
  7. $dirname = __DIR__ . '/';
  8. $file = $dirname . 'test_with_comment.zip';
  9. include $dirname . 'utils.inc';
  10. $zip = new ZipArchive;
  11. if ($zip->open($file) !== TRUE) {
  12. echo "open failed.\n";
  13. exit('failed');
  14. }
  15. $zip->extractTo($dirname . '__oo_extract_tmp');
  16. if (!is_dir($dirname . '__oo_extract_tmp')) {
  17. echo "failed. mkdir\n";
  18. }
  19. if (!is_dir($dirname .'__oo_extract_tmp/foobar')) {
  20. echo "failed. mkdir foobar\n";
  21. }
  22. if (!file_exists($dirname . '__oo_extract_tmp/foobar/baz')) {
  23. echo "failed. extract foobar/baz\n";
  24. } else {
  25. echo file_get_contents($dirname . '__oo_extract_tmp/foobar/baz') . "\n";
  26. }
  27. if (!file_exists($dirname . '__oo_extract_tmp/bar')) {
  28. echo "failed. bar file\n";
  29. } else {
  30. echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n";
  31. }
  32. if (!file_exists($dirname . '__oo_extract_tmp/foo')) {
  33. echo "failed. foo file\n";
  34. } else {
  35. echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n";
  36. }
  37. /* extract one file */
  38. $zip->extractTo($dirname . '__oo_extract_tmp', 'bar');
  39. if (!file_exists($dirname . '__oo_extract_tmp/bar')) {
  40. echo "failed. extract bar file\n";
  41. } else {
  42. echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n";
  43. }
  44. /* extract two files */
  45. $zip->extractTo($dirname . '__oo_extract_tmp', array('bar','foo'));
  46. if (!file_exists($dirname . '__oo_extract_tmp/bar')) {
  47. echo "failed. extract bar file\n";
  48. } else {
  49. echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n";
  50. }
  51. if (!file_exists($dirname . '__oo_extract_tmp/foo')) {
  52. echo "failed. extract foo file\n";
  53. } else {
  54. echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n";
  55. }
  56. rmdir_rf($dirname . '__oo_extract_tmp');
  57. ?>
  58. --EXPECT--
  59. blabla laber rababer sülz
  60. bar
  61. foo
  62. bar
  63. bar
  64. foo