Download a file

function downloadFile($file) {
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($file).'"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        $result = readfile($file);
        unlink($file); // Delete after download and before the exit
        exit;
        if($result===false) {
            return $result;
        } 
    } else {
        return false;
    }
}