unlink
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
unlink
when i try to unlink a directory on a windows machine i get permission denied. this is (i think) becuase of whatever the files '.' and '..' are becuae when i try to delete everything it in first then delete the dir but i get permission denied for those files then permission denied for the folder. how do i get around this?
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
same exact problem. i get permission denied for those . and .. files when trying to delete them. if i try to just delete the whole dir without the files first i get permission denied dir not empty.
how can i get rid of those pesky stupid things?
Code: Select all
Warning: unlink(../gallerys/1/..) [function.unlink]: Permission denied
Warning: unlink(../gallerys/1/.) [function.unlink]: Permission denied
Warning: rmdir(../gallerys/1) [function.rmdir]: Permission deniedUse the commands like this:
Windows doesn't recognise the whole ../. thing. Well, it does, but it's fussy.
Code: Select all
unlink(realpath('../images/image.jpg'));. and .. are not files, they are shortcuts
'.' = current directory and '..' = parent directory.
I just tested this myself, also on windows with the following that I just made up:
And it works..
I have read up a bit, and it appears the PHP.ini directive safe_mode causes problems with functions like these, so check that to ensure it is set to off/0. maybe even include the line in your script before using rmdir?
I just tested this myself, also on windows with the following that I just made up:
Code: Select all
function delDir($dir) {
$dir = realpath($dir);
if (!is_dir($dir)) {
return false;
} else {
$hand = opendir($dir);
while (($file = readdir($hand)) !== false) {
if (($file != '..') && ($file != '.')) {
unlink(realpath($dir . '/' . $file));
}
}
closedir($hand);
chmod($dir, 0777);
if (!rmdir($dir)) {
return false;
}
return true;
}
}I have read up a bit, and it appears the PHP.ini directive safe_mode causes problems with functions like these, so check that to ensure it is set to off/0. maybe even include the line
Code: Select all
ini_set('safe_mode', 0);