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));
?>
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved