Skip to content
Advertisement

Change the target of a symlink with PHP

How can I change the target of a symlink with PHP? Thanks.

Advertisement

Answer

You can delete the existing link using unlink function and recreate the link to the new target using the symlink function.

symlink($target, $link);
.
.
unlink($link);
symlink($new_target, $link);

You need to do error checking for each of these.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement