php8.5
Home/ Manual/ spl / splfileinfo/ SplFileInfo::getLinkTarget

SplFileInfo::getLinkTarget

PHP function Edit on GitHub ✎

(PHP 5 >= 5.2.2, PHP 7, PHP 8)

Gets the target of a link

Description

SplFileInfo::getLinkTarget(): string|false

Gets the target of a filesystem link.

Note

The target may not be the real path on the filesystem. Use SplFileInfo::getRealPath to determine the true path on the filesystem.

Parameters Parameters

Return Values

Returns the target of the filesystem link on success, or false on failure.

Errors/Exceptions

Throws RuntimeException on error.

Examples

SplFileInfo::getLinkTarget() example

php
<?php
$info = new SplFileInfo('/Users/bbieber/workspace');
if ($info->isLink()) {
    var_dump($info->getLinkTarget());
    var_dump($info->getRealPath());
}
?>

The above example will output something similar to:

output
string(19) "Documents/workspace"
string(34) "/Users/bbieber/Documents/workspace"

See Also

  • SplFileInfo::isLink
  • SplFileInfo::getRealPath

Source: reference/spl/splfileinfo/getlinktarget.xml · from the official PHP manual (php/doc-en)