php 文件下载出错
写了一个 文件下载的程序
function download_file($filename){ //below to provide the download if (file_exists($filename)) { $file = fopen($filename); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filename) . ' bytes'); //ob_clean(); //flush(); readfile($filename); fclose($file); return true; }else{ echo("the file not exist"); return false; } //above to provide the download }
if(download_file($filename)){ #下面的操作}else{ #错误提示}
[解决办法]