I am constructing a simple system for uploading zips of images to a site. I need to be able to:
Unpack Zip into temporary folder -> check c开发者_StackOverflow社区ontents -> move to permanent location
Sounds simple enough, but during my test I unpacked a zip file and found a __MACOSX folder, which was interfering with the way I was scanning and checking the files (this folder is unnecessary and will slow things down on larger zip files). I ran a check on a zip file created by Windows XP which showed no unnecessary folders.
My question is, should I be wary of other operating systems/compression suites or is Mac OSX the only system that adds this unnecessary folder, and therefore I just need to check for that one?
I suppose you have no control over what the user can upload, so you should be wary of anything that can happen. It seems that the files in the __MACOSX folder aren't recognized as valid images (at least I can't open them on my computer), so you shouldn't move them to the permanent location. And the same goes for anything that you can't recognize in the zip file. Don't rely on the extension for this. There must be some methods for checking if a file is a valid image or not... I'll update this answer if I find anything useful.
Edit: it seems getimagesize is used to validate images in php.
精彩评论