oo_extract.phpt 1.8 KB

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