If a call to unlink() returns false for the specified path, how do you find out what the reason for the failure was (i.e. EISDIR, ENOENT, ELOOP etc.)? PHP 5.x running on redhat
I don't think it is possible to get back any error code(s) issued by the system. That is maybe down to the fact that PHP is supposed to be portable, and different OS's have different methods of reporting errors.
You could of course do a exec('rm ....')
and get the error level back but that's not very portable, and makes your app depend on exec()
rights.
Otherwise, if you really, really need this, only a very hacky workaround comes to mind: Create a custom error handler function that tries to fetch the reason for the failure from the warning unlink
throws - e.g. check for "Permission denied", or just fetch the whole error message.
Create a wrapper function around unlink
that sets and re-sets the error handler. Something like this:
function my_unlink($file)
{
set_error_handler("my_error_handler");
unlink($file);
restore_error_handler();
}
you get my drift.
If anybody knows a better solution - I'd be interested to hear about it, too....