copy_variation3-win32.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. --TEST--
  2. Test copy() function: usage variations - destination file names(white spaces)
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) != "WIN")
  6. die("skip only 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: In creation of destination file names containing white spaces
  15. and checking the existence and size of destination files
  16. */
  17. echo "*** Test copy() function: destination file names containing whitespaces ***\n";
  18. $file_path = dirname(__FILE__);
  19. $src_file_name = $file_path."/copy_variation3.tmp";
  20. $file_handle = fopen($src_file_name, "w");
  21. fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
  22. fclose($file_handle);
  23. /* array of destination file names */
  24. $dest_files = array(
  25. /* File names containing whitespaces */
  26. "copy variation3.tmp", //file name containing blank space
  27. " copy_variation3.tmp", //file name starts with blank space
  28. "copy\tvariation3.tmp",
  29. " ", //blank space as file name
  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 = $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. if( file_exists($dest_file_name) ) {
  44. echo "Destination file name => ";
  45. print($dest_file_name);
  46. echo "\n";
  47. echo "Size of source file => ";
  48. var_dump( filesize($src_file_name) );
  49. clearstatcache();
  50. echo "Size of destination file => ";
  51. var_dump( filesize($dest_file_name) );
  52. clearstatcache();
  53. unlink($dest_file_name);
  54. }
  55. $count++;
  56. }
  57. echo "*** Done ***\n";
  58. ?>
  59. --CLEAN--
  60. <?php
  61. unlink(dirname(__FILE__)."/copy_variation3.tmp");
  62. ?>
  63. --EXPECTF--
  64. *** Test copy() function: destination file names containing whitespaces ***
  65. Size of the source file before copy operation => int(1500)
  66. -- Now applying copy() on source file to create copies --
  67. -- Iteration 1 --
  68. Copy operation => bool(true)
  69. Existence of destination file => bool(true)
  70. Destination file name => copy variation3.tmp
  71. Size of source file => int(1500)
  72. Size of destination file => int(1500)
  73. -- Iteration 2 --
  74. Copy operation => bool(true)
  75. Existence of destination file => bool(true)
  76. Destination file name => copy_variation3.tmp
  77. Size of source file => int(1500)
  78. Size of destination file => int(1500)
  79. -- Iteration 3 --
  80. Copy operation =>
  81. Warning: copy(%s): %s
  82. bool(false)
  83. Existence of destination file => bool(false)
  84. -- Iteration 4 --
  85. Copy operation =>
  86. Warning: copy(%s): %s
  87. bool(false)
  88. Existence of destination file => bool(false)
  89. *** Done ***