“没有要提取的文件”尝试解压强制下载的 zip 时出现的消息

发布于 2024-10-17 10:55:14 字数 505 浏览 6 评论 0 原文

当我尝试强制提取从服务器下载的 zip 文件夹时,我收到消息“没有要提取的文件”。但是当我直接从服务器下载 zip 文件夹时,我能够正确提取它。这是我用来强制下载的代码。

$file = 'absolute/path/to/the/zip/folder';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@readfile($file); 

有谁知道为什么会发生这种情况?任何帮助将不胜感激。提前致谢

When i try to extract the zip folder that i downloaded from the server forcefully, i get the message, 'no files to extract'. But when i download the zip folder directly from the server, i am able to extract it properly. Here is the code that i used to download forcefully.

$file = 'absolute/path/to/the/zip/folder';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@readfile($file); 

Does anyone know why this is happening? Any help would be appreciated. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁梦 2024-10-24 10:55:14

我无法回答这个问题,但这里有一些可以尝试的想法:

  • 尝试不同的 mimetype,例如通用 application/octet-stream
  • 连接 Fiddler(或任何其他 HTTP 调试器)并查看传输。你看到了什么?文件正在下载吗?也许由于某种原因存在无效的 Content-Length 标头?
  • 正如 @middaparka 在评论中指出的,不要抑制 readfile() 中的错误。

I cannot answer the question, but here are a few ideas to try out:

  • Try a different mimetype, such as the generic application/octet-stream.
  • Attach Fiddler (or any other HTTP debugger) and look at the transfer. What do you see? Is the file being downloaded? Maybe there is an invalid Content-Length header for some reason?
  • As noted by @middaparka in comments, don't suppress errors from readfile().
不即不离 2024-10-24 10:55:14

很难判断这是由于您正在使用的标头还是服务器问题造成的。但是,我通常使用以下内容不会出现任何问题:

header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=".basename($file));

readfile($file);
exit();

因此,您可能想尝试上述内容,看看是否有任何区别。 (据猜测,如果您的连接速度很慢,那么您没有提供 Content-Length 标头这一事实可能对这种情况没有帮助。)

It's tricky to tell if it's due to the headers you're using or a server issue. However, I generally use the following without any problems:

header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=".basename($file));

readfile($file);
exit();

As such, you might want to try the above and see if that makes any difference. (At a guess, if your connection is slow the fact that you're not supplying a Content-Length header might not be helping the situation.)

零崎曲识 2024-10-24 10:55:14

感谢大家的支持。我找到了解决方案。我在发送标头之前使用了 mkdir 函数。这似乎产生了一些错误,因此错误在标头之前输出,从而导致了问题。当我使用“@”运算符抑制错误时,问题得到了解决。 :)。早些时候,我从 fiddler 收到以下消息:“Fiddler 在会话 #4 中检测到协议违规。服务器没有返回格式正确的 HTTP 标头。可能完全丢失(例如 HTTP/0.9),可能只有 \r\r 而不是\r\n\r\n?”

Thank you everybody for your support. I found the solution. I had used mkdir function before headers were sent. It seems this was generating some error, so error was outputted before the headers and thereby causing the problem. When i suppressed the errors using '@' operator, the problem got solved. :). Earlier, i got the following message from fiddler: "Fiddler has detected a protocol violation in session #4. The Server did not return properly formatted HTTP Headers. Maybe missing altogether (e.g. HTTP/0.9), maybe only \r\r instead of \r\n\r\n?"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文