php下载文件

来源:互联网 发布:联通5g网络什么时候出 编辑:程序博客网 时间:2024/05/16 19:33
<? 
if($id=="01X39"){      // 连接提供的要下载的文件ID 
   $fileName="temp01X39.rar";  // 服务器上的文件名 
   $toName="2.rar";    // 实际文件名 

if($id=="01X51"){ 
   $fileName="temp01X51.rar"
   $toName="1.rar"

$path = "./upload/".$fileName;  // 文件保存路径 
if (!file_exists($path)) {  
  Header("http/1.1 404 Not Found");  // 确定文件是否存在 
  exit(); 
}else
  $file = fopen($path,"r");         // 开始下载进程 
  Header("Content-type: application/octet-stream"); 
  Header("Accept-Ranges: bytes"); 
//Header("Accept-Length: ".filesize($path)); 
  Header("Content-Disposition: attachment; filename=".$toName); 
  echo fread($file,filesize($path)); 
  fclose($file); 
  exit(); 

?>
原创粉丝点击