“没有要提取的文件”尝试解压强制下载的 zip 时出现的消息
当我尝试强制提取从服务器下载的 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);
有谁知道为什么会发生这种情况?任何帮助将不胜感激。提前致谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我无法回答这个问题,但这里有一些可以尝试的想法:
application/octet-stream
。readfile()
中的错误。I cannot answer the question, but here are a few ideas to try out:
application/octet-stream
.readfile()
.很难判断这是由于您正在使用的标头还是服务器问题造成的。但是,我通常使用以下内容不会出现任何问题:
因此,您可能想尝试上述内容,看看是否有任何区别。 (据猜测,如果您的连接速度很慢,那么您没有提供 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:
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.)
感谢大家的支持。我找到了解决方案。我在发送标头之前使用了 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?"