Example 1 — Create a Symbolic Link
Create a file, make a link to it, and check that the link exists.
<?php
$dir = sys_get_temp_dir();
$target = $dir . '/sym_target.txt';
$link = $dir . '/sym_link.txt';
file_put_contents($target, 'Hello');
if (symlink($target, $link)) {
echo 'Link created', PHP_EOL;
}
echo 'Is a link: ', is_link($link) ? 'yes' : 'no', PHP_EOL;
unlink($link);
unlink($target); How It Works
- file_put_contents() creates the real file that the link will point to.
- symlink() takes the target first and the new link second.
- is_link() confirms the new path is a symbolic link and not a normal file.
- unlink() removes the link and then the target to clean up.

