copy_variation6.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. --TEST--
  2. Test copy() function: usage variations - copy empty file across dirs
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) == "WIN")
  6. die("skip Do not run on Windows");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype: bool copy ( string $source, string $dest );
  11. Description: Makes a copy of the file source to dest.
  12. Returns TRUE on success or FALSE on failure.
  13. */
  14. /* Test copy() function: Trying to create copy of source file
  15. into different destination dir paths given in various notations */
  16. echo "*** Test copy() function: copying file across directories ***\n";
  17. $base_dir = dirname(__FILE__)."/copy_variation6";
  18. mkdir($base_dir);
  19. $sub_dir = $base_dir."/copy_variation6_sub";
  20. mkdir($sub_dir);
  21. $dirname_with_blank = $sub_dir."/copy variation6";
  22. mkdir($dirname_with_blank);
  23. $src_file_name = dirname(__FILE__)."/copy_variation6.tmp";
  24. fclose( fopen($src_file_name, "w") );
  25. echo "Size of source file => ";
  26. var_dump( filesize($src_file_name) );
  27. clearstatcache();
  28. $dests = array(
  29. $base_dir."/copy_copy_variation6.tmp",
  30. $base_dir."/copy_variation6_sub/copy_copy_variation6.tmp",
  31. "$sub_dir/copy_copy_variation6.tmp",
  32. "$sub_dir/../copy_copy_variation6.tmp",
  33. "$sub_dir/../copy_variation6_sub/copy_copy_variation6.tmp",
  34. "$sub_dir/..///../copy_copy_variation6.tmp",
  35. "$sub_dir/..///../*",
  36. "$dirname_with_blank/copy_copy_variation6.tmp"
  37. );
  38. echo "\n-- Now applying copy() on source file to create copies --";
  39. $count = 1;
  40. foreach($dests as $dest) {
  41. echo "\n-- Iteration $count --\n";
  42. echo "Copy operation => ";
  43. var_dump( copy($src_file_name, $dest) );
  44. echo "Existence of destination file => ";
  45. var_dump( file_exists($dest) );
  46. echo "Destination file name is => ";
  47. print($dest);
  48. echo "\n";
  49. echo "Size of source file => ";
  50. var_dump( filesize($src_file_name) );
  51. clearstatcache();
  52. echo "Size of destination file => ";
  53. var_dump( filesize($dest) );
  54. clearstatcache();
  55. unlink("$dest");
  56. $count++;
  57. }
  58. unlink($src_file_name);
  59. rmdir($dirname_with_blank);
  60. rmdir($sub_dir);
  61. rmdir($base_dir);
  62. echo "*** Done ***\n";
  63. ?>
  64. --EXPECTF--
  65. *** Test copy() function: copying file across directories ***
  66. Size of source file => int(0)
  67. -- Now applying copy() on source file to create copies --
  68. -- Iteration 1 --
  69. Copy operation => bool(true)
  70. Existence of destination file => bool(true)
  71. Destination file name is => %s/copy_variation6/copy_copy_variation6.tmp
  72. Size of source file => int(0)
  73. Size of destination file => int(0)
  74. -- Iteration 2 --
  75. Copy operation => bool(true)
  76. Existence of destination file => bool(true)
  77. Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
  78. Size of source file => int(0)
  79. Size of destination file => int(0)
  80. -- Iteration 3 --
  81. Copy operation => bool(true)
  82. Existence of destination file => bool(true)
  83. Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
  84. Size of source file => int(0)
  85. Size of destination file => int(0)
  86. -- Iteration 4 --
  87. Copy operation => bool(true)
  88. Existence of destination file => bool(true)
  89. Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_copy_variation6.tmp
  90. Size of source file => int(0)
  91. Size of destination file => int(0)
  92. -- Iteration 5 --
  93. Copy operation => bool(true)
  94. Existence of destination file => bool(true)
  95. Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_variation6_sub/copy_copy_variation6.tmp
  96. Size of source file => int(0)
  97. Size of destination file => int(0)
  98. -- Iteration 6 --
  99. Copy operation => bool(true)
  100. Existence of destination file => bool(true)
  101. Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../copy_copy_variation6.tmp
  102. Size of source file => int(0)
  103. Size of destination file => int(0)
  104. -- Iteration 7 --
  105. Copy operation => bool(true)
  106. Existence of destination file => bool(true)
  107. Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../*
  108. Size of source file => int(0)
  109. Size of destination file => int(0)
  110. -- Iteration 8 --
  111. Copy operation => bool(true)
  112. Existence of destination file => bool(true)
  113. Destination file name is => %s/copy_variation6/copy_variation6_sub/copy variation6/copy_copy_variation6.tmp
  114. Size of source file => int(0)
  115. Size of destination file => int(0)
  116. *** Done ***