This handy function will help you to delete files on your webserver without touching any ftp client or pressing your "DELETE" button.
It is very simple but yet so powerful so please always make sure that you delete the right file.
It uses the "unlink" function to destroy our data and it needs 2 parameters: the path to our file (it must end with a trailing slash "/") and the exact name of the victim (file in cause).
The function is set to output 2 possible results, that is, by situation, "TRUE" or "FALSE" in order for your script to continue it's job based on this result. For example if (our function's result was TRUE) { sing a song } elseif (our function's result was FALSE) { turn the radio on }.
function fileDelete($filepath,$filename) {
$success = FALSE;
if (file_exists($filepath.$filename)&&$filename!=""&&$filename!="n/a") {
unlink ($filepath.$filename);
$success = TRUE;
}
return $success;
}