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服务器的地址:

配置服务器




posted @ 2018-07-12 21:47  夯实点  阅读(358)  评论(0编辑  收藏  举报