1--TEST-- 2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & dir perms. 3--SKIPIF-- 4<?php 5if ( substr(PHP_OS, 0, 3) == 'WIN' ) { 6 die('skip no symlinks on Windows'); 7} 8if ( substr(PHP_OS, 0, 3) == 'MAC' ) { 9 die('skip Not valid for MacOS'); 10} 11 12// Skip if being run by root (files are always readable, writeable and executable) 13$filename = dirname(__FILE__)."/symlink_link_linkinfo_is_link6_check_root.tmp"; 14$fp = fopen($filename, 'w'); 15fclose($fp); 16if(fileowner($filename) == 0) { 17 unlink ($filename); 18 die('skip cannot be run as root'); 19} 20 21unlink($filename); 22?> 23--FILE-- 24<?php 25/* Prototype: bool symlink ( string $target, string $link ); 26 Description: creates a symbolic link to the existing target with the specified name link 27 28 Prototype: bool is_link ( string $filename ); 29 Description: Tells whether the given file is a symbolic link. 30 31 Prototype: bool link ( string $target, string $link ); 32 Description: Create a hard link 33 34 Prototype: int linkinfo ( string $path ); 35 Description: Gets information about a link 36*/ 37 38/* Variation 6 : Change permission of directory and try creating links inside that directory */ 39$file_path = dirname(__FILE__); 40 41echo "*** Creating links in a directory without permission to allow the operation ***\n"; 42// temp file used 43$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6"; 44mkdir($dirname); 45$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp"; 46 47// remove all permissions from dir 48var_dump( chmod($dirname, 0000) ); 49 50echo "\n-- Working with soft links --\n"; 51$linkname = "$dirname/non_existent_link_variation5.tmp"; 52 53// expected: false 54var_dump( symlink($filename, $linkname) ); // this link won't get created 55var_dump( linkinfo($linkname) ); 56var_dump( is_link($linkname) ); 57// clear the cache 58clearstatcache(); 59 60echo "\n-- Working with hard links --\n"; 61// expected: false 62var_dump( link($filename, $linkname) ); 63var_dump( linkinfo($linkname) ); 64var_dump( is_link($linkname) ); 65// clear the cache 66clearstatcache(); 67 68chmod($dirname, 0777); // to enable dir deletion 69echo "Done\n"; 70?> 71--CLEAN-- 72<?php 73$file_path = dirname(__FILE__); 74$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6"; 75$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp"; 76if(file_exists($filename)) { 77unlink($filename); 78} 79if(file_exists($dirname)) { 80rmdir($dirname); 81} 82?> 83--EXPECTF-- 84*** Creating links in a directory without permission to allow the operation *** 85bool(true) 86 87-- Working with soft links -- 88 89Warning: symlink(): Permission denied in %s on line %d 90bool(false) 91 92Warning: linkinfo(): Permission denied in %s on line %d 93int(-1) 94bool(false) 95 96-- Working with hard links -- 97 98Warning: link(): Permission denied in %s on line %d 99bool(false) 100 101Warning: linkinfo(): Permission denied in %s on line %d 102int(-1) 103bool(false) 104Done 105