PHP link() Function
The PHP link() function creates a hard link.
Note: This function doesn't work on remote files as the file to be examined must be accessible via the server's filesystem.
Syntax
link(target, link)
Parameters
target |
Required. Specify the target of the link. |
link |
Required. Specify the link name. |
Return Value
Returns true on success or false on failure.
Exceptions
The function fails, and issues E_WARNING, if link already exists, or if target does not exist.
Example:
Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to create a hard link.
<?php $target = 'test.txt'; //this file exists $link = 'sampleTest.ttx'; if(link($target, $link)) { echo "Link has been created.\n"; } else { echo "Link can not be created.\n"; } ?>
The output of the above code will be:
Link has been created.
❮ PHP Filesystem Reference