homepage Welcome to WebmasterWorld Guest from 54.161.175.231
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Workaround for php unlink() under Windows
Solves the issue of readonly folders
Daniel_V




msg:3969033
 5:54 am on Aug 10, 2009 (gmt 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);
else
$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.

 

da_pinky




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved