zoukankan      html  css  js  c++  java
  • http://www.cnblogs.com/

    <?php
    $filename = $_GET['filename'];
    header("Content-type: application/octet-stream");
    header("Content-Length: ".filesize($filename));
    header("Content-Disposition: attachment; filename=$filename");
    $fp = fopen($filename, 'rb');
    fpassthru($fp);
    fclose($fp);
    ?>

    某一种类型文件下载举例

    <?php
    // 这样将会直接输出一个 PDF 文件
    header('Content-type: application/pdf');
    
    // 这样做就会提示下载 PDF 文件 downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');
    
    // 这是 original.pdf 的源文件
    readfile('original.pdf');
    ?>

    某一种类型文件下载举例

            $downfile = $_GET["download"];
            //文件名称带后缀名
            $filename = basename($downfile);
            $filename_info = explode('.', $filename);
            //文件后缀名
            $fileext = $filename_info[count($filename_info)-1];        
            
            header('Content-type: application/'.$fileext);
            header('Content-Disposition: attachment; filename='.$filename);
            readfile($downfile);

    如果只是要将文件输出到标准输出,可以使用 readfile() 会比用 fopen() 更好。

  • 相关阅读:
    JAVA 8学习笔记-第五章
    JAVA 8学习笔记-第一章
    JAVA 8学习笔记-第二章
    MySQL应用
    Mac给iTerm2终端配色
    masOS支持NTFS读写,无需第三方软件
    macOS Apache配置用于支持Python CGI编程
    Vim
    Thrift
    Netflix Hystrix
  • 原文地址:https://www.cnblogs.com/fan-fan/p/3535543.html
Copyright © 2011-2022 走看看