zoukankan      html  css  js  c++  java
  • 文件下载强制保存,不直接打开,php响应头

    header('Content-Description: File Transfer');
    header('Cache-Control: private, must-revalidate,
    post-check=0, pre-check=0, max-age=1');

    //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
    header('Pragma: public');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

    // force download dialog
    if (strpos(php_sapi_name(), 'cgi') === false) {
        header('Content-Type: application/force-download');
        header('Content-Type: application/octet-stream', false);
        header('Content-Type: application/download', false);
        header('Content-Type: application/pdf', false);
    } else {
        header('Content-Type: application/pdf');
    }


    // use the Content-Disposition header to supply a recommended filename
    header('Content-Disposition: attachment; filename="'.basename($name).'";');
    header('Content-Transfer-Encoding: binary');

    //----- 如果有插件支持, 则在浏览器直接打开的php响应头 -----
    header('Content-Type: application/pdf');
    header('Cache-Control: private, must-revalidate,
    post-check=0, pre-check=0, max-age=1');
    //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
    header('Pragma: public');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header('Content-Disposition: inline; filename="'.basename($name).'";');

  • 相关阅读:
    ng2-bootstrap的modal嵌套时无法滚动的情况
    oracle自动补0
    webservice 从客户端中检测到有潜在危险的 Request.Form 值
    树莓派花生壳
    ubuntu E: Could not get lock /var/lib/dpkg/lock
    树莓派配置静态ip
    解决PL/SQL查询结果乱码的问题
    批处理脚本命令行方式关闭Windows服务
    最简单的分享到微博代码
    Select的onchange事件
  • 原文地址:https://www.cnblogs.com/uniqid/p/4154638.html
Copyright © 2011-2022 走看看