Because of PHP\'s unlink()
not supporting exceptions natively, I\'m making a wrapper function for it. It should throw a FileNotFoundException
if, w
I believe it(i.e. your code) should be portable enough as it is... As regards a better way to achieve the same thing, i would do things differently (although the code is simple, it's also more readable...so bear with me)
function deleteFile($file_path){
if(!is_file($file_path)){
throw new Exception("The path does not seem to point to a valid file");
}
if(!file_exists($file_path)){
throw new Exception("File not found!");
}
if(unlink($file_path)){
return true;
} else {
throw new Exception("File deletion failed!");
}
}
Of course you can always compress and improve on the code...hop this helps!