copy_variation1.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. Test copy() function: usage variations - destination file names(numerics/strings)
  3. --FILE--
  4. <?php
  5. /* Test copy() function: In creation of destination file names containing numerics/strings
  6. and checking the existence and size of destination files
  7. */
  8. echo "*** Test copy() function: destination file names containing numerics/strings ***\n";
  9. $file_path = __DIR__;
  10. $src_file_name = $file_path."/copy_variation1.tmp";
  11. $file_handle = fopen($src_file_name, "w");
  12. fwrite( $file_handle, str_repeat("Hello2World...\n", 100) );
  13. fclose($file_handle);
  14. /* array of destination file names */
  15. $dest_files = array(
  16. /* File names containing numerics, strings */
  17. "copy.tmp", //regular file name
  18. "copy_copy_variation1.tmp",
  19. ".tmp", //file name only with extension
  20. "123.tmp", //file name starts with numeric and with regular extension
  21. "copy_variation1.123", //file name with numeric extension
  22. "123", //numeric
  23. "123copy_variation1.tmp", //file name containing numeric & string
  24. "copy_variation.tmp123", //file name containing string & numeric
  25. chr(99).chr(111).chr(112).chr(121).chr(49).".tmp" //file name containing ASCII values
  26. );
  27. echo "Size of the source file before copy operation => ";
  28. var_dump( filesize("$src_file_name") );
  29. clearstatcache();
  30. echo "\n-- Now applying copy() on source file to create copies --";
  31. $count = 1;
  32. foreach($dest_files as $dest_file) {
  33. echo "\n-- Iteration $count --\n";
  34. $dest_file_name = "$file_path/$dest_file";
  35. echo "Copy operation => ";
  36. var_dump( copy($src_file_name, $dest_file_name) );
  37. echo "Existence of destination file => ";
  38. var_dump( file_exists($dest_file_name) );
  39. echo "Destination file name => ";
  40. print($dest_file_name);
  41. echo "\n";
  42. echo "Size of source file => ";
  43. var_dump( filesize($src_file_name) );
  44. clearstatcache();
  45. echo "Size of destination file => ";
  46. var_dump( filesize($dest_file_name) );
  47. clearstatcache();
  48. unlink($dest_file_name);
  49. $count++;
  50. }
  51. echo "*** Done ***\n";
  52. ?>
  53. --CLEAN--
  54. <?php
  55. unlink(__DIR__."/copy_variation1.tmp");
  56. ?>
  57. --EXPECTF--
  58. *** Test copy() function: destination file names containing numerics/strings ***
  59. Size of the source file before copy operation => int(1500)
  60. -- Now applying copy() on source file to create copies --
  61. -- Iteration 1 --
  62. Copy operation => bool(true)
  63. Existence of destination file => bool(true)
  64. Destination file name => %s/copy.tmp
  65. Size of source file => int(1500)
  66. Size of destination file => int(1500)
  67. -- Iteration 2 --
  68. Copy operation => bool(true)
  69. Existence of destination file => bool(true)
  70. Destination file name => %s/copy_copy_variation1.tmp
  71. Size of source file => int(1500)
  72. Size of destination file => int(1500)
  73. -- Iteration 3 --
  74. Copy operation => bool(true)
  75. Existence of destination file => bool(true)
  76. Destination file name => %s/.tmp
  77. Size of source file => int(1500)
  78. Size of destination file => int(1500)
  79. -- Iteration 4 --
  80. Copy operation => bool(true)
  81. Existence of destination file => bool(true)
  82. Destination file name => %s/123.tmp
  83. Size of source file => int(1500)
  84. Size of destination file => int(1500)
  85. -- Iteration 5 --
  86. Copy operation => bool(true)
  87. Existence of destination file => bool(true)
  88. Destination file name => %s/copy_variation1.123
  89. Size of source file => int(1500)
  90. Size of destination file => int(1500)
  91. -- Iteration 6 --
  92. Copy operation => bool(true)
  93. Existence of destination file => bool(true)
  94. Destination file name => %s/123
  95. Size of source file => int(1500)
  96. Size of destination file => int(1500)
  97. -- Iteration 7 --
  98. Copy operation => bool(true)
  99. Existence of destination file => bool(true)
  100. Destination file name => %s/123copy_variation1.tmp
  101. Size of source file => int(1500)
  102. Size of destination file => int(1500)
  103. -- Iteration 8 --
  104. Copy operation => bool(true)
  105. Existence of destination file => bool(true)
  106. Destination file name => %s/copy_variation.tmp123
  107. Size of source file => int(1500)
  108. Size of destination file => int(1500)
  109. -- Iteration 9 --
  110. Copy operation => bool(true)
  111. Existence of destination file => bool(true)
  112. Destination file name => %s/copy1.tmp
  113. Size of source file => int(1500)
  114. Size of destination file => int(1500)
  115. *** Done ***