1--TEST-- 2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link with same name in diff. dir 3--SKIPIF-- 4<?php 5if (PHP_OS_FAMILY === 'Windows') { 6 require_once __DIR__ . '/windows_links/common.inc'; 7 skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__); 8} 9?> 10--FILE-- 11<?php 12/* Prototype: bool symlink ( string $target, string $link ); 13 Description: creates a symbolic link to the existing target with the specified name link 14 15 Prototype: bool is_link ( string $filename ); 16 Description: Tells whether the given file is a symbolic link. 17 18 Prototype: bool link ( string $target, string $link ); 19 Description: Create a hard link 20 21 Prototype: int linkinfo ( string $path ); 22 Description: Gets information about a link 23*/ 24 25/* Variation 8 : Create soft/hard link to different directory */ 26 27/* creating link to a file in different dir with the same name as the file */ 28echo "\n*** Create hard link in different directory with same filename ***\n"; 29// temp file used 30$file_path = __DIR__; 31$filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp"; 32// temp link name used 33$dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8"; 34mkdir($dirname); 35$linkname = "symlink_link_linkinfo_is_link_variation8.tmp"; 36// create temp file 37$fp = fopen($filename, "w"); 38fclose($fp); 39 40var_dump( link($filename, $dirname."/") ); // this fails indicating file exists 41// ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link 42var_dump( link($filename, $dirname."/".$linkname) ); // this works fine 43// delete link 44unlink($dirname."/".$linkname); 45// delete temp file 46unlink($filename); 47// delete temp dir 48rmdir($dirname); 49 50echo "\n*** Create soft link in different directory with same filename ***\n"; 51$filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp"; 52// temp link name used 53$dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8"; 54mkdir($dirname); 55$linkname = "symlink_link_linkinfo_is_link_variation8.tmp"; 56// create temp file 57$fp = fopen($filename, "w"); 58fclose($fp); 59 60var_dump( symlink($filename, $dirname."/") ); // this fails indicating file exists 61// ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link 62var_dump( symlink($filename, $dirname."/".$linkname) ); // this works fine 63// delete link 64unlink($dirname."/".$linkname); 65// delete temp file 66unlink($filename); 67// delete temp dir 68rmdir($dirname); 69 70echo "Done\n"; 71?> 72--EXPECTF-- 73*** Create hard link in different directory with same filename *** 74 75Warning: link(): File exists in %s on line %d 76bool(false) 77bool(true) 78 79*** Create soft link in different directory with same filename *** 80 81Warning: symlink(): %rFile exists|Permission denied%r in %s on line %d 82bool(false) 83bool(true) 84Done 85