1--TEST-- 2Test copy() function: usage variations - copy empty file across dirs 3--SKIPIF-- 4<?php 5if(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 15/* Test copy() function: Trying to create copy of source file 16 into different destination dir paths given in various notations */ 17 18echo "*** Test copy() function: copying file across directories ***\n"; 19$base_dir = __DIR__."/copy_variation6"; 20mkdir($base_dir); 21 22$sub_dir = $base_dir."/copy_variation6_sub"; 23mkdir($sub_dir); 24 25$dirname_with_blank = $sub_dir."/copy variation6"; 26mkdir($dirname_with_blank); 27 28$src_file_name = __DIR__."/copy_variation6.tmp"; 29fclose( fopen($src_file_name, "w") ); 30 31echo "Size of source file => "; 32var_dump( filesize($src_file_name) ); 33clearstatcache(); 34 35$dests = array( 36 $base_dir."/copy_copy_variation6.tmp", 37 $base_dir."/copy_variation6_sub/copy_copy_variation6.tmp", 38 "$sub_dir/copy_copy_variation6.tmp", 39 "$sub_dir/../copy_copy_variation6.tmp", 40 "$sub_dir/../copy_variation6_sub/copy_copy_variation6.tmp", 41 "$sub_dir/..///../copy_copy_variation6.tmp", 42 "$sub_dir///../*", 43 "$dirname_with_blank/copy_copy_variation6.tmp" 44); 45 46echo "\n-- Now applying copy() on source file to create copies --"; 47$count = 1; 48foreach($dests as $dest) { 49 echo "\n-- Iteration $count --\n"; 50 51 echo "Copy operation => "; 52 var_dump( copy($src_file_name, $dest) ); 53 54 echo "Existence of destination file => "; 55 var_dump( file_exists($dest) ); 56 57 if( file_exists($dest) ) { 58 echo "Destination file name is => "; 59 print($dest); 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) ); 68 clearstatcache(); 69 70 unlink("$dest"); 71 } 72 73 $count++; 74} 75 76unlink($src_file_name); 77rmdir($dirname_with_blank); 78rmdir($sub_dir); 79rmdir($base_dir); 80 81echo "*** Done ***\n"; 82?> 83--EXPECTF-- 84*** Test copy() function: copying file across directories *** 85Size of source file => int(0) 86 87-- Now applying copy() on source file to create copies -- 88-- Iteration 1 -- 89Copy operation => bool(true) 90Existence of destination file => bool(true) 91Destination file name is => %s/copy_variation6/copy_copy_variation6.tmp 92Size of source file => int(0) 93Size of destination file => int(0) 94 95-- Iteration 2 -- 96Copy operation => bool(true) 97Existence of destination file => bool(true) 98Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp 99Size of source file => int(0) 100Size of destination file => int(0) 101 102-- Iteration 3 -- 103Copy operation => bool(true) 104Existence of destination file => bool(true) 105Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp 106Size of source file => int(0) 107Size of destination file => int(0) 108 109-- Iteration 4 -- 110Copy operation => bool(true) 111Existence of destination file => bool(true) 112Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_copy_variation6.tmp 113Size of source file => int(0) 114Size of destination file => int(0) 115 116-- Iteration 5 -- 117Copy operation => bool(true) 118Existence of destination file => bool(true) 119Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_variation6_sub/copy_copy_variation6.tmp 120Size of source file => int(0) 121Size of destination file => int(0) 122 123-- Iteration 6 -- 124Copy operation => bool(true) 125Existence of destination file => bool(true) 126Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../copy_copy_variation6.tmp 127Size of source file => int(0) 128Size of destination file => int(0) 129 130-- Iteration 7 -- 131Copy operation => 132Warning: copy(%s/copy_variation6/copy_variation6_sub///../*): failed to open stream: No such file or directory in %s on line %d 133bool(false) 134Existence of destination file => bool(false) 135 136-- Iteration 8 -- 137Copy operation => bool(true) 138Existence of destination file => bool(true) 139Destination file name is => %s/copy_variation6/copy_variation6_sub/copy variation6/copy_copy_variation6.tmp 140Size of source file => int(0) 141Size of destination file => int(0) 142*** Done *** 143