PHP - unlink() returning true, but not deleting file

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
I am using the following PHP function to recursively delete directories:
PHP:
class Classname{
//...

public function rmdir($dir) {
	if (is_dir($dir)) {
		$objects = scandir($dir);
		foreach ($objects as $object) {
			if ($object != "." && $object != "..") {
				chmod("$dir/$object", 0777);
				if (filetype("$dir/$object") == "dir")
					$this->rmdir("$dir/$object");
				else unlink("$dir/$object");
			}
		}
		reset($objects);
		rmdir($dir);
	} 
}

//...
}
The unlink() call is returning false (i tested it by wrapping it in a var_dump() call), but the file is not being deleted. I really have no idea what is wrong here. Help?
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Are the files chowed to your account?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Is unlink returning true or false? The thread title says one thing, your post another. If it's returning false, use set_error_handler to capture the error or error_reporting (temporarily) to output it. The former is what you should do in production code, the latter for quick & dirty debugging.
 
Top