If you keep getting permission denied errors on windows when using PHP’s
unlink function, and you already checked permissions, it’s probably the read-only flag on the file. I don’t know why PHP does this, but it won’t delete a file marked read-only. Thanks to a Daniel V for pointing this out and saving me a lot of time.
@chmod($dir, 0777) seems to clear the read-only flag, as pointed out by hodgman at ali dot com dot au PHP’s chmod docs.
Also, make sure the file isn’t still open for reading, as that will also prevent unlike from doing its job. It’s somewhat common to want to read a file and then delete it, and sometimes easy to forget to close it before doing so.