How do I remove a symlink with PHP on windows?
Running this:
mkdir('test');
symlink('test', 'test2');
unlink('test2');
Gives the following error:
PHP Warning: unlink(test2): Permission denied in C:\path\to\app\testlink.php on line 4
PHP Stack trace:
PHP 1. {main}() C:\path\to\app\testlink.php:0
PHP 2. unlink() C:\path\to\app\testlink.php:4
The directory and symlink were made correctly, just not removed.
Running:
To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link (<SYMLINK>) of a file, to delete a symbolic link use the del command.
Remove a Symbolic Link using the rm command You can also use the -i flag with the rm command to prompt for confirmation. After that, you can use the ls -l command to confirm if the symlink has been removed. That is all there is to it!
The symlink() function in PHP is an inbuilt function which is used to create a symbolic link for a target which already exists. It helps to create a specific name link for a target. The target and link names are sent as parameters to the symlink() function and it returns True on success and False on failure.
The symbolic link does not contain any data, but you can perform all operations on the symbolic link file. Removing a symbolic link does not delete the original file, but deleting a file makes the symlink a dangling link. In this guide, we will learn how to remove symbolic links using unlink and rm commands.
Ok, I figured it out. So Ill leave this here for future reference:
To remove a symlink to a directory use the rmdir
function:
mkdir('test');
symlink('test', 'test2');
rmdir('test2');
unlink
is for removing files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With