zoukankan      html  css  js  c++  java
  • PHP浏览器强制下载pdf文件,浏览器提示502问题

    刚刚学习PHP,做一个强制下载文件时,测试了一下PDF强制下载,居然提示502...

    这个是代码,反复确认是没问题的...

    //让浏览器强制下载文件
    function download($filepath){
        if ((isset($filepath))&&(file_exists($filepath))){
            header("Content-length: ".filesize($filepath));
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . substr($filepath,strrpos($filepath, '/')+1, strlen($filepath)) . '"');
            readfile("$filepath");
        } else {
            echo "Looks like file does not exist!";
        }
    } 

    最后发现问题是PhpStorm 2018.1.6 版本内置服务器有问题,直接运行测试一直报这个502错...

    我更改成Apache服务器再测试就没问题了。

    下面地址是我参考更改Apache服务器的地址:

    配置服务器




  • 相关阅读:
    三范式
    解决Linux下乱码
    ER概念模型
    20140607
    PHP Fatal error: Class 'Yaf_Application' not found
    PHP流式读取XML文件
    php反射的使用
    wget 和curl 进行post数据
    crontab
    Leetcode OJ: Gray Code
  • 原文地址:https://www.cnblogs.com/qq1995/p/10359011.html
Copyright © 2011-2022 走看看