1--TEST-- 2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & dir perms. 3--SKIPIF-- 4<?php 5require __DIR__ . '/../skipif_root.inc'; 6?> 7--FILE-- 8<?php 9/* Prototype: bool symlink ( string $target, string $link ); 10 Description: creates a symbolic link to the existing target with the specified name link 11 12 Prototype: bool is_link ( string $filename ); 13 Description: Tells whether the given file is a symbolic link. 14 15 Prototype: bool link ( string $target, string $link ); 16 Description: Create a hard link 17 18 Prototype: int linkinfo ( string $path ); 19 Description: Gets information about a link 20*/ 21 22/* Variation 6 : Change permission of directory and try creating links inside that directory */ 23$file_path = __DIR__; 24 25echo "*** Creating links in a directory without permission to allow the operation ***\n"; 26// temp file used 27$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6"; 28mkdir($dirname); 29$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp"; 30 31// remove all permissions from dir 32var_dump( chmod($dirname, 0000) ); 33 34echo "\n-- Working with soft links --\n"; 35$linkname = "$dirname/non_existent_link_variation5.tmp"; 36 37// expected: false 38var_dump( symlink($filename, $linkname) ); // this link won't get created 39var_dump( linkinfo($linkname) ); 40var_dump( is_link($linkname) ); 41// clear the cache 42clearstatcache(); 43 44echo "\n-- Working with hard links --\n"; 45// expected: false 46var_dump( link($filename, $linkname) ); 47var_dump( linkinfo($linkname) ); 48var_dump( is_link($linkname) ); 49// clear the cache 50clearstatcache(); 51 52chmod($dirname, 0777); // to enable dir deletion 53echo "Done\n"; 54?> 55--CLEAN-- 56<?php 57$file_path = __DIR__; 58$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6"; 59$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp"; 60if(file_exists($filename)) { 61unlink($filename); 62} 63if(file_exists($dirname)) { 64rmdir($dirname); 65} 66?> 67--EXPECTF-- 68*** Creating links in a directory without permission to allow the operation *** 69bool(true) 70 71-- Working with soft links -- 72 73Warning: symlink(): Permission denied in %s on line %d 74bool(false) 75 76Warning: linkinfo(): Permission denied in %s on line %d 77int(-1) 78bool(false) 79 80-- Working with hard links -- 81 82Warning: link(): Permission denied in %s on line %d 83bool(false) 84 85Warning: linkinfo(): Permission denied in %s on line %d 86int(-1) 87bool(false) 88Done 89