1

我的代码,路径正确,内容长度正确

header("X-Sendfile: " . $savePath); 
header('Content-Length: ' . filesize($savePath));
header("Content-type: $type");
header('Content-Disposition: attachment; filename="' . basename($localFilename) . '"');

exit();

我的 .htaccess

<Files file.php>
    XSendFile on
</Files>

这总是会导致下载大小为零的文件。

该文件肯定在那里并且在正确的位置。使用 curl -I向我展示了以下似乎很好。但是文件仍然是零字节。

HTTP/1.1 200 OK
Date: Sat, 21 Feb 2015 11:35:37 GMT
Server: Apache/2.2.29 (Amazon)
X-Powered-By: PHP/5.3.29
X-Sendfile: /var/www/html/cache/72b08eb707bb5eab58d8e5d7d9b21bb8.jpeg
Content-Length: 10004
Content-Disposition: attachment; filename="72b08eb707bb5eab58d8e5d7d9b21bb8.jpeg"
Connection: close
Content-Type: image/jpeg

我做错了什么?

4

1 回答 1

3

所以事实证明你需要使用

XSendFile on

在您的主要 Apache2 conf 中,否则它将无法在任何地方工作

于 2015-02-22T22:33:39.870 回答