1--TEST-- 2Test copy() function: usage variations - copying links across dirs 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) == "WIN") 6 die("skip Invalid for 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/* Trying to copy the links across dir paths given in various notations 16 and dirs having limited access */ 17 18echo "*** Testing copy() function: copying links across different directories ***\n"; 19 20$file_path = dirname(__FILE__); 21 22$base_dir = $file_path."/copy_variation8"; 23mkdir($base_dir); 24$sub_dir = $base_dir."/copy_variation8_sub"; 25mkdir($sub_dir); 26$dirname_with_blank = $sub_dir."/copy variation6"; 27mkdir($dirname_with_blank); 28 29$file = $file_path."/copy_variation8.tmp"; 30fclose( fopen($file, "w") ); 31 32$symlink = $file_path."/copy_variation8_symlink.tmp"; 33$hardlink = $file_path."/copy_variation8_hardlink.tmp"; 34 35symlink($file, $symlink); //creating symlink 36link($file, $hardlink); //creating hardlink 37 38$dests = array( 39 $base_dir."/copy_copy_variation8.tmp", 40 $base_dir."/copy_variation8_sub/copy_copy_variation8.tmp", 41 "$sub_dir/copy_copy_variation8.tmp", 42 "$sub_dir/../copy_copy_variation8.tmp", 43 "$sub_dir/../copy_variation8_sub/copy_copy_variation8.tmp", 44 "$sub_dir/..///../copy_copy_variation8.tmp", 45 "$sub_dir/..///../*", 46 "$dirname_with_blank/copy_copy_variation8.tmp" 47); 48 49$count = 1; 50foreach($dests as $dest) { 51 echo "\n-- Iteration $count --\n"; 52 echo "- With symlink -\n"; 53 var_dump( copy($symlink, $dest) ); 54 var_dump( file_exists($dest) ); 55 var_dump( is_link($dest) ); //expected: bool(false) 56 var_dump( is_file($dest) ); //expected: bool(true) 57 clearstatcache(); 58 unlink("$dest"); 59 echo "- With hardlink -\n"; 60 var_dump( copy($hardlink, $dest) ); 61 var_dump( file_exists($dest) ); 62 var_dump( is_link($dest) ); //expected: bool(flase) 63 var_dump( is_file($dest) ); //expected: bool(true) 64 clearstatcache(); 65 unlink("$dest"); 66 $count++; 67} 68 69unlink($symlink); 70unlink($hardlink); 71unlink($file); 72rmdir($dirname_with_blank); 73rmdir($sub_dir); 74rmdir($base_dir); 75 76echo "*** Done ***\n"; 77?> 78--EXPECTF-- 79*** Testing copy() function: copying links across different directories *** 80 81-- Iteration 1 -- 82- With symlink - 83bool(true) 84bool(true) 85bool(false) 86bool(true) 87- With hardlink - 88bool(true) 89bool(true) 90bool(false) 91bool(true) 92 93-- Iteration 2 -- 94- With symlink - 95bool(true) 96bool(true) 97bool(false) 98bool(true) 99- With hardlink - 100bool(true) 101bool(true) 102bool(false) 103bool(true) 104 105-- Iteration 3 -- 106- With symlink - 107bool(true) 108bool(true) 109bool(false) 110bool(true) 111- With hardlink - 112bool(true) 113bool(true) 114bool(false) 115bool(true) 116 117-- Iteration 4 -- 118- With symlink - 119bool(true) 120bool(true) 121bool(false) 122bool(true) 123- With hardlink - 124bool(true) 125bool(true) 126bool(false) 127bool(true) 128 129-- Iteration 5 -- 130- With symlink - 131bool(true) 132bool(true) 133bool(false) 134bool(true) 135- With hardlink - 136bool(true) 137bool(true) 138bool(false) 139bool(true) 140 141-- Iteration 6 -- 142- With symlink - 143bool(true) 144bool(true) 145bool(false) 146bool(true) 147- With hardlink - 148bool(true) 149bool(true) 150bool(false) 151bool(true) 152 153-- Iteration 7 -- 154- With symlink - 155bool(true) 156bool(true) 157bool(false) 158bool(true) 159- With hardlink - 160bool(true) 161bool(true) 162bool(false) 163bool(true) 164 165-- Iteration 8 -- 166- With symlink - 167bool(true) 168bool(true) 169bool(false) 170bool(true) 171- With hardlink - 172bool(true) 173bool(true) 174bool(false) 175bool(true) 176*** Done *** 177