>  기사  >  백엔드 개발  >  PHP文件下载示例

PHP文件下载示例

WBOY
WBOY원래의
2016-06-23 13:39:35918검색

<?php header("Content-type:text/html;charset=utf-8"); // $file_name="cookie.jpg"; $file_name="3D.exe"; //用以解决中文不能显示出来的问题 $file_name=iconv("utf-8","gb2312",$file_name); $file_sub_path=$_SERVER['DOCUMENT_ROOT']."/"; echo "<br/>file_sub_path:".$file_sub_path."<br>";$file_path=$file_sub_path.$file_name; echo "<br>filepath:".$file_path."<br>";//首先要判断给定的文件存在与否 if(!file_exists($file_path)){ echo "没有该文件文件"; return ; } $fp=fopen($file_path,"r"); $file_size=filesize($file_path); //下载文件需要用到的头 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length:".$file_size); Header("Content-Disposition: attachment; filename=".$file_name); $buffer=1024; $file_count=0; //向浏览器返回数据 while(!feof($fp) && $file_count

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.