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() 更好。

  • 相关阅读:
    c#配置文件
    C#预处理指令
    C#面向对象详解
    231. Power of Two
    226. Invert Binary Tree
    C语言函数入参压栈顺序为什么是从右向左?
    对C++ 虚函数的理解
    悲观锁和乐观锁
    什么是索引
    CHAR 和VARCHAR的区别
  • 原文地址:https://www.cnblogs.com/fan-fan/p/3535543.html
Copyright © 2011-2022 走看看