php 文件下载功能

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



下面是word.php页面



[php] view plaincopy
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.}  
原文地址:https://www.cnblogs.com/lijun2013/p/3781851.html