简体   繁体   English

从PHP生成的ZIP可与winrar一起使用,但不能与其他人一起使用?

[英]ZIP generated from PHP works with winrar but not others?

I have some PHP code which allows users to submit files. 我有一些PHP代码,允许用户提交文件。 I then can download the ZIP file. 然后,我可以下载ZIP文件。 If I use windows with Winrar, it unzips fine, I can open my files and that's all good. 如果我将Windows与Winrar一起使用,则可以将其解压缩,然后打开文件,一切都很好。 I have tested this on multiple computers. 我已经在多台计算机上对此进行了测试。

If I don't have winrar and I use the default unzipper in Windows 8 or Windows 7 (or OSX), I get a message which says that the zip file is invalid. 如果我没有winrar,并且在Windows 8或Windows 7(或OSX)中使用默认的解压缩程序,则会收到一条消息,指出该zip文件无效。

Are there any known issues that I have been unable to find? 是否有我找不到的已知问题? Does anyone know what could cause this behaviour? 有谁知道会导致这种行为的原因吗?

Thanks, 谢谢,

Here is a link to the output zip. 这是输出zip的链接。 https://www.dropbox.com/s/imvzixl3y3l12l1/TestAreaForMax-aa-57.zip https://www.dropbox.com/s/imvzixl3y3l12l1/TestAreaForMax-aa-57.zip

Without seeing your code and ZIP file nobody will tell for sure, but I recall having similar issue and it appeared my script was throwing some error messages which ended up in produced ZIP archive. 没有看到您的代码和ZIP文件,没人会确定,但是我记得有类似的问题,而且我的脚本似乎抛出了一些错误消息,这些消息最终出现在生成的ZIP归档文件中。 Some unzip managed to recover from this, others did not, so I suggest to open your ZIP file in any text editor and see if you got nothing like PHP Warning message in the beginning of the file. 有些解压缩可以从中恢复,而其他解压缩则无法恢复,因此我建议在任何文本编辑器中打开您的ZIP文件,并查看文件开头是否没有类似PHP警告消息的信息。

EDIT 编辑

Regular zip file starts with "PK" . 常规zip文件以"PK"开头。 Your file starts with " PK" so unless you are not really need that, remove ?> from PHP script that produces your zip file (and I'd suggest removing this from all scripts) as there's one space somewhere which does what I described above, and most likely it lurks after ?> 您的文件以" PK"开头,因此,除非您不是真的需要,否则从生成您的zip文件的PHP脚本中删除?> (我建议从所有脚本中删除它),因为某处有一个空间可以执行上述操作,很可能在之后潜伏?>

If you are in PHP code block, then white space does nothing. 如果您使用的是PHP代码块,则空白什么也不做。 But by placing ?> you tell PHP when your scripts ends. 但是通过放置?>您可以告诉PHP脚本何时结束。 And outside PHP code block, white space is just being sent to the client. 在PHP代码块之外,空格仅被发送到客户端。 So if you keep ?> and the space is after it then it will be sent. 因此,如果保留?>并且空格在它后面,那么它将被发送。 And if output of your script is something downloadable, said space will "join" the byte stream user saves. 如果脚本的输出是可下载的,则该空间将“加入”用户保存的字节流。 By removing ?> you are not telling explicitly PHP where your code ends, and in that case it will automatically end with end of source file. 通过删除?>,您不会明确告诉PHP代码的结尾,在这种情况下,它将自动以源文件结尾结束。 And white space is a bitch to track as usually it is "invisible" due to editor settings (and for that reason I set my syntax highlighting to show spaces in different color than background color is) 由于编辑器设置的原因,空白通常很容易被跟踪,因此空白(因此我将语法突出显示设置为以不同于背景色的颜色显示空白)

In general, for reason above, it is always good NOT use ?> if you do not mix PHP code with anything (ie HTML). 通常,由于上述原因,如果您不将PHP代码与任何内容(即HTML)混合使用,最好不要使用?> It always help to configure your editor to auto-trim trailing whitespaces on save 它总是有助于将编辑器配置为在保存时自动修剪尾随空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM