gpt4 book ai didi

PHP readfile 返回零长度文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:33:51 27 4
gpt4 key购买 nike

这很很奇怪

我有一个脚本可以通过浏览器将本地 zip 文件发送给用户。到目前为止,该脚本运行良好,没有任何问题。今天我的同事通知我脚本正在发送零长度文件。

一些背景信息:

  • 在脚本出错之前没有修改服务器设置
  • 测试了不同的浏览器(在 Chrome/Firefox 上相同)
  • 以前的 zip 文件(以前运行良好)也是零长度
  • 脚本在服务器上找到文件
  • 文件大小(回显调试时)是正确的
  • 试图将服务器设置和脚本调整为 adviced here没有成功。

更新:

  • is_readable() 返回 1
  • 文件大小可能在 5Mb 到 100Mb 之间(不具体)
  • $zip_file 保存文件路径
  • $zip_name 保存 zip 名称
  • 文件实际上是零长度的(在文本编辑器中打开它不包含一个字节)
  • error_reportingOn (E_ALL) 什么都不显示
  • 没有标题,浏览器会正确显示 zip“源”
  • Safari 说:'0 字节?无法解码原始数据'第一个有用的(?)症状

有问题的片段:

if (file_exists($zip_file)) {
header('Content-type: application/zip');
header('Content-disposition: filename="' . $zip_name . '"');
header("Content-length: " . filesize($zip_file));
readfile($zip_file);
exit();
}

我怎样才能轻松调试它?

提前致谢,法布里克

最佳答案

http://www.php.net/manual/en/function.readfile.php#102137 :

It should be noted that in the example:

header('Content-Length: ' . filesize($file));

$file should really be the full path to the file. Otherwise content length will not always be set, often resulting in the dreaded "0 byte file" problem.

关于PHP readfile 返回零长度文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5375143/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com