简体   繁体   中英

ZIP generated from PHP works with winrar but not others?

I have some PHP code which allows users to submit files. I then can download the ZIP file. If I use windows with Winrar, it unzips fine, I can open my files and that's all good. 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.

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. 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. 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.

EDIT

Regular zip file starts with "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 ?>

If you are in PHP code block, then white space does nothing. But by placing ?> you tell PHP when your scripts ends. And outside PHP code block, white space is just being sent to the client. 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. 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). It always help to configure your editor to auto-trim trailing whitespaces on save

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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