Delete file from server

Simple example how to delete file with PHP from your server when use unlink.

Delete file from server


$file="file.jpeg";
if (file_exists($file)){ ///chek is file exist.
    if(unlink($file)){
       echo "File deleted";
    }
}else{
     echo "File is not exists";
}

Delete file from server directory


$path="/images/file.jpeg";
if (file_exists($path)){ ///chek is file exist.
    if(unlink($path)){
       echo "File deleted";
    }
}else{
     echo "File is not exists";
}