PHP is_link() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Filesystem

Definition

In PHP, is_link() tells you whether a path is a symbolic link (symlink). A symbolic link is a small shortcut file that points to another file or folder.

Most file checks follow the link and look at the target. is_link() looks at the link itself, so it can tell you that a path is a shortcut even when the target is missing.

Syntax

Call is_link() with the values you need. Start with this line.

PHP
$isLink = is_link('shortcut.txt');
CallWhat it does
is_link('shortcut.txt')Returns true if shortcut.txt is a symbolic link.
is_link('real.txt')Returns false for a normal file.
is_link('missing')Returns false when nothing exists at that path.

Creating symbolic links on Windows may need administrator rights or Developer Mode, so the examples on this page are easiest to run on Linux or macOS. is_link() itself is safe to call on every system.

Library declarations
PHP
is_link(string $filename): bool

Parameters

ParameterDescription
filenameRequired. The path to check.

Return Value

Return ValueDescription
boolReturns true if the path exists and is a symbolic link, otherwise false.

PHP Examples

Example 1 — Detect a Symbolic Link

Create a file and a symbolic link to it, then compare the answers of is_link().

PHP
<?php
$target = sys_get_temp_dir() . '/is_link_target.txt';
$link   = sys_get_temp_dir() . '/is_link_shortcut.txt';

file_put_contents($target, 'data');
@unlink($link);
symlink($target, $link);

echo "Link: ", is_link($link) ? 'yes' : 'no', PHP_EOL;
echo "Target: ", is_link($target) ? 'yes' : 'no', PHP_EOL;

unlink($link);
unlink($target);

How It Works

  1. The target file is created and any old link with the same name is removed.
  2. symlink() makes a new link that points to the target.
  3. is_link() returns true for the shortcut and false for the real file.
  4. Both are removed at the end with unlink().

Example 2 — Broken Links Still Count as Links

If the target is missing, file_exists() says false but is_link() still says true.

PHP
<?php
$link = sys_get_temp_dir() . '/is_link_broken.txt';
$file = sys_get_temp_dir() . '/is_link_plain.txt';

file_put_contents($file, 'x');
@unlink($link);
symlink(sys_get_temp_dir() . '/does-not-exist.txt', $link);

echo "Regular file: ", is_link($file) ? 'yes' : 'no', PHP_EOL;
echo "Missing path: ", is_link($file . '.missing') ? 'yes' : 'no', PHP_EOL;
echo "Broken link: ", is_link($link) ? 'yes' : 'no', PHP_EOL;
echo "file_exists on broken link: ", file_exists($link) ? 'yes' : 'no', PHP_EOL;

unlink($link);
unlink($file);

How It Works

  1. A normal file and a missing path are not links, so both checks return false.
  2. The symlink points to a target that does not exist, which makes it a broken link.
  3. is_link() looks at the link itself and returns true.
  4. file_exists() follows the link to the missing target and returns false.

Example 3 — Read Where a Link Points

After you confirm a path is a link, use readlink() to see its target.

PHP
<?php
$target = sys_get_temp_dir() . '/is_link_a.txt';
$link   = sys_get_temp_dir() . '/is_link_b.txt';

file_put_contents($target, 'data');
@unlink($link);
symlink($target, $link);

if (is_link($link)) {
    echo "Link points to: ", basename(readlink($link)), PHP_EOL;
}

unlink($link);
unlink($target);

How It Works

  1. The link is created with symlink() and points to is_link_a. txt.
  2. is_link() confirms that the path is a link, so readlink() is safe to call.
  3. readlink() returns the full target path and basename() keeps only the file name.
  4. Both temporary paths are deleted at the end.

Frequently Asked Questions

It checks whether a path is a symbolic link and returns true or false. It looks at the link itself, not at its target.
is_file() follows the link and checks the target, while is_link() checks the link. A link to a file gives true for both.
That happens with a broken link. The shortcut exists, but its target is gone, so file_exists() follows it and finds nothing.
Call readlink($path). It returns the target path as a string, or false if the path is not a link.
Yes, it works on modern Windows for symbolic links, but creating links may need extra rights.

Next: is_readable()

is_readable() tells you whether a file or folder exists and PHP is allowed to read it. It .

is_readable() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful