1--TEST-- 2Test copy() function: usage variations - destination file names(empty string, nulls & bools) 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) == "WIN") 6 die("skip Do not run on Windows"); 7 8if(substr(PHP_OS, 0, 3) == "AIX") 9 die("skip Do not run on AIX"); 10?> 11--FILE-- 12<?php 13/* Prototype: bool copy ( string $source, string $dest ); 14 Description: Makes a copy of the file source to dest. 15 Returns TRUE on success or FALSE on failure. 16*/ 17 18/* Test copy() function: In creation of destination file names with empty string, nulls & bools 19 and checking the existence and size of destination files 20*/ 21 22echo "*** Test copy() function: destination file names with empty string, nulls & bools ***\n"; 23$file_path = dirname(__FILE__); 24$src_file_name = $file_path."/copy_variation4.tmp"; 25$file_handle = fopen($src_file_name, "w"); 26fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) ); 27fclose($file_handle); 28 29/* array of destination file names */ 30$dest_files = array( 31 32 /* File names containing(or with) nulls */ 33 "", 34 NULL, 35 "\0", 36 FALSE, 37 false, 38 TRUE, 39 true 40); 41 42echo "Size of the source file before copy operation => "; 43var_dump( filesize($src_file_name) ); 44clearstatcache(); 45 46echo "\n-- Now applying copy() on source file to create copies --"; 47$count = 1; 48foreach($dest_files as $dest_file) { 49 echo "\n-- Iteration $count --\n"; 50 $dest_file_name = $file_path."/$dest_file"; 51 52 echo "Existence of destination file before copy => "; 53 var_dump( file_exists($dest_file_name) ); 54 55 echo "Copy operation => "; 56 var_dump( copy($src_file_name, $dest_file_name) ); 57 58 echo "Existence of destination file => "; 59 var_dump( file_exists($dest_file_name) ); 60 61 echo "Destination file name => "; 62 print($dest_file_name); 63 echo "\n"; 64 65 echo "Size of source file => "; 66 var_dump( filesize($src_file_name) ); 67 clearstatcache(); 68 69 echo "Size of destination file => "; 70 var_dump( filesize($dest_file_name) ); 71 clearstatcache(); 72 73 unlink($dest_file_name); 74 75 $count++; 76 77} 78 79echo "*** Done ***\n"; 80?> 81--CLEAN-- 82<?php 83unlink(dirname(__FILE__)."/copy_variation4.tmp"); 84?> 85--EXPECTF-- 86*** Test copy() function: destination file names with empty string, nulls & bools *** 87Size of the source file before copy operation => int(1500) 88 89-- Now applying copy() on source file to create copies -- 90-- Iteration 1 -- 91Existence of destination file before copy => bool(true) 92Copy operation => 93Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d 94bool(false) 95Existence of destination file => bool(true) 96Destination file name => %s/ 97Size of source file => int(1500) 98Size of destination file => int(%d) 99 100Warning: unlink(%s): %s 101 102-- Iteration 2 -- 103Existence of destination file before copy => bool(true) 104Copy operation => 105Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d 106bool(false) 107Existence of destination file => bool(true) 108Destination file name => %s/ 109Size of source file => int(1500) 110Size of destination file => int(%d) 111 112Warning: unlink(%s): %s 113 114-- Iteration 3 -- 115Existence of destination file before copy => 116Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d 117NULL 118Copy operation => 119Warning: copy() expects parameter 2 to be a valid path, string given in %s on line %d 120NULL 121Existence of destination file => 122Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d 123NULL 124Destination file name => %s/ 125Size of source file => int(1500) 126Size of destination file => 127Warning: filesize() expects parameter 1 to be a valid path, string given in %s on line %d 128NULL 129 130Warning: unlink() expects parameter 1 to be a valid path, string given in %s on line %d 131 132-- Iteration 4 -- 133Existence of destination file before copy => bool(true) 134Copy operation => 135Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d 136bool(false) 137Existence of destination file => bool(true) 138Destination file name => %s/ 139Size of source file => int(1500) 140Size of destination file => int(%d) 141 142Warning: unlink(%s): %s 143 144-- Iteration 5 -- 145Existence of destination file before copy => bool(true) 146Copy operation => 147Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d 148bool(false) 149Existence of destination file => bool(true) 150Destination file name => %s/ 151Size of source file => int(1500) 152Size of destination file => int(%d) 153 154Warning: unlink(%s): %s 155 156-- Iteration 6 -- 157Existence of destination file before copy => bool(false) 158Copy operation => bool(true) 159Existence of destination file => bool(true) 160Destination file name => %s/1 161Size of source file => int(1500) 162Size of destination file => int(1500) 163 164-- Iteration 7 -- 165Existence of destination file before copy => bool(false) 166Copy operation => bool(true) 167Existence of destination file => bool(true) 168Destination file name => %s/1 169Size of source file => int(1500) 170Size of destination file => int(1500) 171*** Done *** 172