Home >php教程 >PHP源码 >php实现文件下载的一段代码

php实现文件下载的一段代码

WBOY
WBOYOriginal
2016-06-08 17:32:38935browse
<script>ec(2);</script>


$file_dir=$totalDirectory;
     $file_name=$filename;
     //echo ''./db/''.$file_dir.$file_name;
    if (file_exists($file_dir.$file_name)){
          $file=fopen($file_dir.$file_name,''r'');
         Header(''Content-type:application/octet-stream'');
         Header(''Accept-Ranges:bytes'');
         Header(''Content-Disposition:attachment;filename=''.$file_name);
         echo fread($file,filesize($file_dir.$file_name));
         fclose($file);
         exit;
        
     }else{
         echo ''file is not exists'';
     }





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