function file_dload($file, $name = 'test.txt', $type = 'application/octet-stream', $del = 1) { ob_end_clean(); ob_start(); header('Content-Description: File Transfer'); header('Content-Type: '.$type); header('Content-Disposition: attachment; filename=' . $name); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($str)); readfile($file); if($del) unlink($file); flush(); return true; }