Page 1 of 1

unlink

Posted: Mon Oct 24, 2005 4:08 pm
by shiznatix
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?

Posted: Tue Oct 25, 2005 12:23 am
by Jenk

Posted: Tue Oct 25, 2005 3:11 am
by shiznatix
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.

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 denied
how can i get rid of those pesky stupid things?

Posted: Tue Oct 25, 2005 3:21 am
by Jenk
Ensure you have the correct permissions, and that the files are not in use.

Posted: Tue Oct 25, 2005 4:00 am
by shiznatix
its a windows computer, there are no permissons. the folder is not in use as it can be deleted by just going to my hard drive and hitting delete. everything else in the folder gets deleted no problem so i don't see why these files that are not really there are stopping me from deleting the folder.

Posted: Tue Oct 25, 2005 4:02 am
by Jenk
Use the commands like this:

Code: Select all

unlink(realpath('../images/image.jpg'));
Windows doesn't recognise the whole ../. thing. Well, it does, but it's fussy.

Posted: Tue Oct 25, 2005 4:44 am
by shiznatix
same problem. its still these damned . and .. files that won't delete

Posted: Tue Oct 25, 2005 5:27 am
by Jenk
. 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:

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;
	}
}
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

Code: Select all

ini_set('safe_mode', 0);
in your script before using rmdir?

Posted: Tue Oct 25, 2005 6:13 am
by shiznatix
ok that works. the problem was i would open the dir and look at the pictures and it would make a thumbs.db and whatnot. if i dont open the folder on my computer ever it works fine. stupid things. thanks

Posted: Tue Oct 25, 2005 6:16 am
by Jenk
Aye, one of the many things listed on annoyances.org.