PHP做文件下载功能

下载的文件和PHP代码页面放到同一目录下

<a href="word.php?file=help&type=doc">宽带故障排查手册下载</a>  

下面是word.php页面

01.if (!isset(GET["file"]) || !isset(GET["type"])) {   
02.print "no file selsect"; exit();  
03.}  
04.$file = GET["file"].".".GET["type"];  
05.if (@$fp = fopen($file,'r')){  
06. header ("Content-type: octet/stream");  
07. if (strstr(SERVER["HTTP_USER_AGENT"], "MSIE")){  
08. header("Content-Disposition: filename=".mb_convert_encoding('宽带用户故障诊断处理手册.doc','GB2312','UTF-8')); // For IE  
09. }else{  
10. header("Content-Disposition: attachment; filename=".mb_convert_encoding('宽带用户故障诊断处理手册.doc','GB2312','UTF-8')); // For Other browsers   
11.} while(!@feof($fp)){  
12. echo fread($fp,1024);   
13.}   
14.//@fpassthru($fp);  
15. exit();   
16.} else{  
17. print "此文件不存在";  
18.}  

 

posted @ 2013-05-21 10:40  王翔(kingfly)  阅读(339)  评论(0编辑  收藏  举报