PHP Function Reference

PHP readlink() Function



The PHP readlink() function returns the target of a symbolic link.

Syntax

readlink(path)

Parameters

path Required. Specify the path to symbolic link.

Return Value

Returns the target of the symbolic link or false on error.

Note: The function fails if path is not a symlink, except on Windows, where the normalized path will be returned.

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 get the target of the created 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";
}

echo readlink($link)."\n";
?>

The output of the above code will be:

Symbolic link has been created.
test.txt

❮ PHP Filesystem Reference