php用header()实现文件下载功能代码:
<p>function download($file_url,$new_name=''){</p> if(!isset($file_url)||trim($file_url)==''){<br /> return '500';<br /> }<br /> if(!file_exists($file_url)){//检查文件是否存在<br /> return '404';<br /> }<br /> $file_name=basename($file_url);<br /> $file_type=explode('.',$file_url);<br /> $file_type=$file_type[count($file_type)-1];<br /> $file_name=trim($new_name=='')?$file_name:urlencode($new_name).'.'.$file_type;<br /> //输入文件标签phpernote<br /> header("Content-type: application/octet-stream");<br /> header("Accept-Ranges: bytes");<br /> header("Accept-Length: ".filesize($file_url));<br /> header("Content-Disposition: attachment; filename=".$file_name);<br /> //输出文件内容<br /> @readfile($file_type);<br />}