PHP | link( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The link() creates a hard link for a specified target. The target and the link are passed as parameters to the link() function and it returns true on success and false on failure.Syntax: link(target, link) Parameters Used: The link() function in PHP accepts two parameters. target : It is a mandatory parameter which specifies the target.link : It is an mandatory parameter which specifies the name of the link. Return Value: It returns TRUE on success or FALSE on failure. Errors And Exception The link() function does not work on remote files as the file to be examined must be accessible via the server's filesystem.The link created by the link() function is not an HTML link, but a link in the filesystem..In linux, hardlinking to a directory is not permitted. Examples: Input : $targetfile = 'gfg.txt.'; $linkname = 'gfglink'; link($targetfile, $linkname); Output : 1 Input : $targetfile = 'gfg.txt.'; $linkname = 'gfglink'; if(!link($targetfile, $linkname)) { echo('Link has been created!'); } else { echo('Link cannot be created!'); } Output : Link has been created! Below programs illustrate the link() function.Program 1 php <?php // target file $targetfile = 'gfg.txt'; // name of the link $linkname = 'gfglink'; // creating a symbolic link for the target file link($targetfile, $linkname); ?> Output: 1 Program 2 php <?php // target file $targetfile = 'gfg.txt'; // name of the link $linkname = 'gfglink'; // creating a symbolic link for the target file if(!link($targetfile, $linkname)) { echo('Link has been created!'); } else { echo('Link cannot be created!'); } ?> Output: Link has been created! Related Article: PHP | symlink( ) functionReference: http://www.php.net/manual/en/function.link.php Create Quiz Comment S Shubrodeep Banerjee Follow 0 Improve S Shubrodeep Banerjee Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-file-handling PHP-function +1 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like