【问题标题】:502 Bad Gateway When Using Header Content-Length使用 Header Content-Length 时出现 502 Bad Gateway
【发布时间】:2015-10-15 10:50:53
【问题描述】:

我试图在用户访问此站点时强制浏览器下载 mp3。我遇到的问题是,如果我设置 Content-Length 标头,页面会引发 502 Bad Gateway 错误,如果我不这样做,它会尝试下载文件,但文件大小为 0 字节。该网站恰好在运行 wordpress。任何方向将不胜感激。我不熟悉wordpress。

    $file = '../uploads/2015/01/Thunder.mp3';
    header('Content-type: application/mp3');
    header("Content-Disposition: attachment; filename=\"$file\"");
    header('Content-Length: '.filesize($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');

【问题讨论】:

    标签: php wordpress download http-headers


    【解决方案1】:

    尝试添加:

    readfile($file);
    

    之后:

    header('Pragma: public');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 2018-08-09
      • 2016-10-23
      • 1970-01-01
      相关资源
      最近更新 更多