copy_variation1.phpt 4.2 KB

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