PHP symlink() Function
The PHP symlink() function creates a symbolic link to the existing target with the specified name 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
symlink(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. On Windows, the function also fails, and issues E_WARNING, 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 symbolic link.
<?php $target = 'test.txt'; $link = 'sampleTest'; if(symlink($target, $link)) { echo "Symbolic link has been created.\n"; } else { echo "Symbolic link can not be created.\n"; } ?>
The output of the above code will be:
Symbolic link has been created.
❮ PHP Filesystem Reference