Home  >  Article  >  Backend Development  >  php-下载效能

php-下载效能

WBOY
WBOYOriginal
2016-06-13 11:55:52756browse

php---下载功能

<?php $filename="胡主席好.pdf";      if(!file_exists($filename))   {     echo "不存在此文件";     return;   }      $fp=fopen($filename,"r");   $file_size=filesize($filename);      //配置头文件      //返回文件类型   header("content-type:application/octet-stream");   //按照字节大小返回   header("Accept-Ranges:bytes");   //返回文件的大小   header("Accept-Length:$file_size");   //客户端弹出一个对话框   header("Content-Disposition:attachment;filename=".$filename);      //向客户端回送数据   $buffer=2048*5;      while(!feof($fp))   {     $file_data = fread($fp,$buffer);          //会送到浏览器     echo $file_data;   }   fclose($fp);   ?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn