PHP Tutorial - PHP readlink() Function






Definition

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

Syntax

PHP readlink() Function has the following syntax.

readlink(linkpath)

Parameter

ParameterIs RequiredDescription
linkpathRequired.Link path to check

Return

This function returns the target of the link on success, or FALSE on failure.

Note

This function is not implemented on Windows platforms.





Example

PHP readlink() function takes a link name and returns the target that the link points to.


<?php
$target = readlink("/home/andrew/myfile.txt");
print $target;
?>

Example 2

The following code shows how to check if the filename is a symbolic link.


<?php
$link = 'images';

if (is_link($link)) {
    echo(readlink($link));
} else {
    symlink('uploads.php', $link);
}
?>