zoukankan      html  css  js  c++  java
  • php 下载文件

     1     public function test(){
     2          $file_name ='/Upload/a1.html';
     3          $filePath = $_SERVER['DOCUMENT_ROOT'].$file_name;
     4             
     5             $out_filename = '附件'.'.'.end(explode('.', $file_name));
     6             file_down($filePath, $file_name,$out_filename);
     7 
     8             
     9             header('Accept-Ranges: bytes');
    10             header('Accept-Length: ' . filesize($filePath));
    11             header('Content-Transfer-Encoding: binary');
    12             header('Content-type: application/octet-stream');
    13             header('Content-Disposition: attachment; filename=' . $out_filename);
    14             header('Content-Type: application/octet-stream; name=' . $out_filename);
    15 
    16             if(is_file($filename) && is_readable($filename)){
    17                 $file = fopen($filename, "r");
    18                 echo fread($file, filesize($filename));
    19                 fclose($file);
    20             }
    21     }
    22 
    23     // 生成快捷方式  可以通下载特定html 文件 当做网站 快捷方式 
    24     public function  kjfs(){
    25         $filename = "/Upload/test.html";
    26         header("Content-Type: application/force-download");
    27         header("Content-Disposition: attachment; filename=".$filename);
    28 
    29         readfile($filename); 
    30     }
  • 相关阅读:
    Storybook 最新教程
    Monorepo All In One
    zsh & git alias
    vue-cli emit webpack config
    iflab隔壁ios组新生面试题
    [转]sprintf
    python版归并排序
    关于linux下GCC生成共享库(动态链接库)的探究
    ubuntu不小心删除了libc-bin的恢复办法
    python实现栈
  • 原文地址:https://www.cnblogs.com/zx1989031/p/5151531.html
Copyright © 2011-2022 走看看