Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Workaround for php unlink() under Windows

Solves the issue of readonly folders



5:54 am on Aug 10, 2009 (gmt 0)

5+ Year Member

Well I whish that it boiled down to a permission issue for everybody! In my case it has not.

unlink() fails permanently under php/windows with a 'permission denied' error; this is despite all privileges being adequate. It seems that it is caused by the readonly flag, which is permanently set on Windows XP folders, where it means something completely different (a problem which the various posts on the net, including Microsoft's KB, do not help to resolve). My best guess is that the php unlink() function verifies this flag and does not even attemp the operation.

So, when all else had failed, I had to design a workaround. Fortunately, it works fine:

if ($windows_environment)
exec("DEL /F/Q \"$filepath\"", $lines, $errno);
$errno = unlink($filepath);

A similar solution works for directories, using the Windows RD command.

Be sure to quote the $filepath in the exec command, otherwise file paths which have spaces in them will cause to command to fail.

I hope this helps.

But I concur that a greater help would be for the php team to realize that this problem is real and to fix it.


9:23 am on Aug 10, 2009 (gmt 0)

10+ Year Member

i used unlink() under windows (xampp & iis) and never had any problems with it. works in php 4 and 5 for me...?

Featured Threads

Hot Threads This Week

Hot Threads This Month