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)

New User

5+ Year Member

joined:Aug 10, 2009
posts: 1
votes: 0

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)

New User

10+ Year Member

joined:Aug 3, 2005
posts: 12
votes: 0

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members