Search code examples
phpsymlinkunlink

PHP unlink for symlink pointing actually not existing file is not working


I have a strange issue with unlink.

when I use unlink() function, it removes the symlink which is linked to existing file correctly. But for the symlink file which is actually pointing un-existing file, it does not work.

I have googled here and there, but can not find the right reason.

The working flow is like this: first PHP file removes the source file (which is triggered by ajax request) and then second php file tries to remove the symlink which is pointing the file just removed by first PHP file. But second PHP file fails to remove the symlink.

Any idea why this kind of thing is happening?


Solution

  • Well, it is due to file_exists() function. Before unlink the file, it checks to see if file is exists using file_exists() function.

    But the problem is this function returns false if symlink is invalid.