1--TEST-- 2Test copy() function: usage variations - copy data 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 "*** Testing copy() function: copying data file across directories ***\n"; 19$base_dir = dirname(__FILE__)."/copy_variation16"; 20mkdir($base_dir); 21 22$sub_dir = $base_dir."/copy_variation16_sub"; 23mkdir($sub_dir); 24 25$dirname_with_blank = $sub_dir."/copy variation16"; 26mkdir($dirname_with_blank); 27 28$src_file_name = dirname(__FILE__)."/copy_variation16.tmp"; 29$file_handle = fopen($src_file_name, "w"); 30fwrite($file_handle, str_repeat("Hello world, this is 2007 year ...\n", 100)); 31fclose($file_handle); 32 33echo "- Size of source file => "; 34var_dump( filesize($src_file_name) ); 35clearstatcache(); 36 37$dests = array( 38 $base_dir."/copy_copy_variation16.tmp", 39 $base_dir."/copy_variation16_sub/copy_copy_variation16.tmp", 40 "$sub_dir/copy_copy_variation16.tmp", 41 "$sub_dir/../copy_copy_variation16.tmp", 42 "$sub_dir/../copy_variation16_sub/copy_copy_variation16.tmp", 43 "$sub_dir/..///../copy_copy_variation16.tmp", 44 "$sub_dir/..///../*", 45 "$dirname_with_blank/copy_copy_variation16.tmp" 46); 47 48echo "\n--- Now applying copy() on source file to create copies ---"; 49$count = 1; 50foreach($dests as $dest) { 51 echo "\n-- Iteration $count --\n"; 52 53 echo "Size of source file => "; 54 var_dump( filesize($src_file_name) ); 55 56 echo "Copy operation => "; 57 var_dump( copy($src_file_name, $dest) ); 58 59 echo "Existence of destination file => "; 60 var_dump( file_exists($dest) ); 61 62 echo "Destination file name is => "; 63 print($dest); 64 echo "\n"; 65 66 echo "Size of destination file => "; 67 var_dump( filesize($dest) ); 68 clearstatcache(); 69 70 unlink("$dest"); 71 72 $count++; 73} 74 75unlink($src_file_name); 76rmdir($dirname_with_blank); 77rmdir($sub_dir); 78rmdir($base_dir); 79 80echo "*** Done ***\n"; 81?> 82--EXPECTF-- 83*** Testing copy() function: copying data file across directories *** 84- Size of source file => int(3500) 85 86--- Now applying copy() on source file to create copies --- 87-- Iteration 1 -- 88Size of source file => int(3500) 89Copy operation => bool(true) 90Existence of destination file => bool(true) 91Destination file name is => %s/copy_variation16/copy_copy_variation16.tmp 92Size of destination file => int(3500) 93 94-- Iteration 2 -- 95Size of source file => int(3500) 96Copy operation => bool(true) 97Existence of destination file => bool(true) 98Destination file name is => %s/copy_variation16/copy_variation16_sub/copy_copy_variation16.tmp 99Size of destination file => int(3500) 100 101-- Iteration 3 -- 102Size of source file => int(3500) 103Copy operation => bool(true) 104Existence of destination file => bool(true) 105Destination file name is => %s/copy_variation16/copy_variation16_sub/copy_copy_variation16.tmp 106Size of destination file => int(3500) 107 108-- Iteration 4 -- 109Size of source file => int(3500) 110Copy operation => bool(true) 111Existence of destination file => bool(true) 112Destination file name is => %s/copy_variation16/copy_variation16_sub/../copy_copy_variation16.tmp 113Size of destination file => int(3500) 114 115-- Iteration 5 -- 116Size of source file => int(3500) 117Copy operation => bool(true) 118Existence of destination file => bool(true) 119Destination file name is => %s/copy_variation16/copy_variation16_sub/../copy_variation16_sub/copy_copy_variation16.tmp 120Size of destination file => int(3500) 121 122-- Iteration 6 -- 123Size of source file => int(3500) 124Copy operation => bool(true) 125Existence of destination file => bool(true) 126Destination file name is => %s/copy_variation16/copy_variation16_sub/..///../copy_copy_variation16.tmp 127Size of destination file => int(3500) 128 129-- Iteration 7 -- 130Size of source file => int(3500) 131Copy operation => bool(true) 132Existence of destination file => bool(true) 133Destination file name is => %s/copy_variation16/copy_variation16_sub/..///../* 134Size of destination file => int(3500) 135 136-- Iteration 8 -- 137Size of source file => int(3500) 138Copy operation => bool(true) 139Existence of destination file => bool(true) 140Destination file name is => %s/copy_variation16/copy_variation16_sub/copy variation16/copy_copy_variation16.tmp 141Size of destination file => int(3500) 142*** Done *** 143