【问题标题】:PHP can't display image using X-SendFile and jpeg headersPHP 无法使用 X-SendFile 和 jpeg 标头显示图像
【发布时间】:2014-04-07 13:49:46
【问题描述】:

由于某种原因,我无法正确显示图像,它抛出的错误并没有告诉我出了什么问题,有什么想法吗?

代码

$finfo = finfo_open(FILEINFO_MIME_TYPE);
header("Content-type:   ".finfo_file($finfo, $filepath));
finfo_close($finfo);
header('Content-length: '.filesize($filepath));
header('Content-Disposition: inline; filename="'.$file.'"');
header('X-Sendfile: ' . $filepath );

标题

HTTP/1.1 200 OK
Date: Mon, 07 Apr 2014 13:45:37 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.10
X-Sendfile: /path/image.jpg
Content-Length: 0
Content-Disposition: inline; filename="image.jpg"
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/jpeg

【问题讨论】:

  • 这确实有效,结果 x-sendfile 配置不正确。

标签: php apache .htaccess http-headers x-sendfile


【解决方案1】:

你确定你的文件在那里吗?

我看到Content-Length: 0。我怀疑你想发送空文件。

尝试删除 headers 输出并将其替换为 echos 以查看您的脚本失败的位置。

【讨论】:

  • 没关系修复它,原来 x-sendfile 没有加载由于 apache config 中指定的不正确目录
【解决方案2】:

上面的代码确实有效,是x-sendfile在apache中没有正确配置

【讨论】:

    猜你喜欢
    • 2012-06-30
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2020-03-26
    • 1970-01-01
    相关资源
    最近更新 更多