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 Do not 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 = dirname(__FILE__)."/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 = dirname(__FILE__)."/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 echo "Destination file name is => "; 58 print($dest); 59 echo "\n"; 60 61 echo "Size of source file => "; 62 var_dump( filesize($src_file_name) ); 63 clearstatcache(); 64 65 echo "Size of destination file => "; 66 var_dump( filesize($dest) ); 67 clearstatcache(); 68 69 unlink("$dest"); 70 71 $count++; 72} 73 74unlink($src_file_name); 75rmdir($dirname_with_blank); 76rmdir($sub_dir); 77rmdir($base_dir); 78 79echo "*** Done ***\n"; 80?> 81 82--EXPECTF-- 83*** Test copy() function: copying file across directories *** 84Size of source file => int(0) 85 86-- Now applying copy() on source file to create copies -- 87-- Iteration 1 -- 88Copy operation => bool(true) 89Existence of destination file => bool(true) 90Destination file name is => %s/copy_variation6/copy_copy_variation6.tmp 91Size of source file => int(0) 92Size of destination file => int(0) 93 94-- Iteration 2 -- 95Copy operation => bool(true) 96Existence of destination file => bool(true) 97Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp 98Size of source file => int(0) 99Size of destination file => int(0) 100 101-- Iteration 3 -- 102Copy operation => bool(true) 103Existence of destination file => bool(true) 104Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp 105Size of source file => int(0) 106Size of destination file => int(0) 107 108-- Iteration 4 -- 109Copy operation => bool(true) 110Existence of destination file => bool(true) 111Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_copy_variation6.tmp 112Size of source file => int(0) 113Size of destination file => int(0) 114 115-- Iteration 5 -- 116Copy operation => bool(true) 117Existence of destination file => bool(true) 118Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_variation6_sub/copy_copy_variation6.tmp 119Size of source file => int(0) 120Size of destination file => int(0) 121 122-- Iteration 6 -- 123Copy operation => bool(true) 124Existence of destination file => bool(true) 125Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../copy_copy_variation6.tmp 126Size of source file => int(0) 127Size of destination file => int(0) 128 129-- Iteration 7 -- 130Copy operation => bool(true) 131Existence of destination file => bool(true) 132Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../* 133Size of source file => int(0) 134Size of destination file => int(0) 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