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