What is the symlink() function in PHP?
symlink() is a built-in function in PHP that is used to create a symbolic link for a target that already exists.
Syntax
symlink(string $target, string $link): bool
Parameters
-
target: The target file for which the symbolic link needs to be created. -
link: The name of the symbolic link.
Return value
symlink() returns True upon success and False upon failure.
Code
In the following code, we create a symbolic link for the temp.txt file and name it temporary.
After creating the symbolic link, we use the readlink() function, which returns the target of the symbolic link to verify that temporary points to the temp.txt file as intended.
main.php
temp.txt
<?php$target = 'temp.txt';$link = 'temporary';symlink($target, $link);print_r(readlink($link));?>
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved