RE: Spam:[PHP] Error Reporting for file commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> [snip]
> When the script tries to delete a file, we always check (using
> file_exists) to see whether the file exists before it's deleted.
>
> The check comes back true, but the unlink then fails, saying no file or
> directory there!
> [/snip]
>
> Could you please post the code you are using to check and unlink the
> file?

Heres the function - sometimes the scandir fails, sometimes the unlink,
sometimes the rmdir at the end.  They all have @ to try and surpress the
error, but I think it's a system halt failure - I can only assume?

You'll also see there are quite a lot of clearstatcache - that was another
attempt to sort this problem out!

function system_rmdir($dir) {
	$current_error_level = error_level();
	error_reporting(0);
	$dir = $dir."/";
	$dir=str_replace("//", "/", $dir);
	clearstatcache();
	if (is_dir($dir)) {
		$dir_contents = scandir($dir);
		foreach ($dir_contents as $item) {
			clearstatcache();
			if (is_dir($dir.$item) && $item != '.' && $item !=
'..') {
				system_rmdir($dir.$item.'/');
			} elseif (file_exists($dir.$item) && $item != '.' &&
$item != '..') {
				@unlink($dir.$item);
			}
		}
		clearstatcache();
		if (is_dir($dir)) {
			@rmdir($dir);
		}
	}
	error_reporting($current_error_level);
}

Thanks
Nunners

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux