Example 1 — Detect a Symbolic Link
Create a file and a symbolic link to it, then compare the answers of is_link().
<?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
- The target file is created and any old link with the same name is removed.
- symlink() makes a new link that points to the target.
- is_link() returns true for the shortcut and false for the real file.
- Both are removed at the end with unlink().

