WordPress php返回zip文件头

时间:2016-04-10 19:45:52

标签: php wordpress

我正在尝试在WordPress中的外部API端点中实现强制下载内容(Zip文件)。

以下是我的代码部分:

$filename = "info.zip";
$filepath = WP_CONTENT_DIR ."/info_folder/info_sub/";
$fulla = $filepath.$filename;
if (headers_sent()) {
    echo 'HTTP header already sent';
} else {
    if (!is_file($fulla)) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
        echo 'File not found';
    } else if (!is_readable($fulla)) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
        echo 'File not readable';
    } else {
        header('content-type: application/zip; charset=utf-8');
        header('Content-disposition: attachment; filename=' . $filename);
        header('Content-Length: ' . filesize($fulla));
        readfile($fulla);
        exit;
    }
}

问题:
在chrome中,它显示 ERR_INVALID_RESPONSE

这就是我作为标题输出获得的内容:

HTTP/1.1 404 Not Found
Connection: keep-alive
Content-disposition: attachment; filename=info.zip
Content-Length: 286
Content-Type: application/zip; charset=utf-8
Date: Sun, 10 Apr 2016 19:35:51 GMT

任何人都可以告诉我到底出错了什么?

0 个答案:

没有答案