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