Help creating ZIP files Windows won't block
I've made an application that takes tagged versions of a project from an hg repository and creates a downloadable ZIP file of that the tagged revision.
The files are created on a MediaTemple server running Linux using CodeIgniter's ZIP Encoding Library. Everything works fine... on a Mac. But, when I download the files on a Windows computer, the archive is blocked from being extracted.
The ZIP contains .html
, .css
, .gif
, .png
and .js
files, and I am pretty sure the .js
files are the securit开发者_如何学运维y culprit, but I am wondering why I can download the Jcrop jQuery plugin (or any other examples) as a ZIP file and extract it without Windows ever interfering, even though it obviously contains .js
files, but something about my ZIP file is posing a security risk.
Normally I would just find a quick software workaround for my particular situation, but since the plan is to sell access to these files, a quick software fix or an FAQ doesn't seem very user-friendly.
Any feedback would be greatly appreciated! Let me know if you need more info.
You can download an example file here.
EDIT:
- I am running Windows XP
- I am not running anti-virus
- The warning is: Windows has blocked access to these files to help protect your computer
- I've unblocked the file but that does nothing
- The file is on my desktop
EDIT 2:
- I added an example file at the bottom. Or you can see it here
- I have only used default extraction tools on XP and Windows 7.
- The ZIP appears to be empty on Windows and I can't see or open any of the files.
EDIT 3:
- From the comments and answers, it appears that the file names were the problem due to an extra
/
being added somewhere in the process. I've uploaded an new example download generated by my app with the file name fix, which you can download here. Please let me know if that fixes the problem.
Indeed, the leading '/' is what's causing the zip to not be allowed to be extracted. I've proven this by writing a Python script to create a modified version of the zip file without the absolute file paths:
from zipfile import *
orig = ZipFile('download.zip', 'r')
fixed = ZipFile('fixed.zip', 'w')
for fileinfo in orig.infolist():
fixed.writestr(fileinfo.filename[1:], orig.read(fileinfo.filename))
fixed.close()
(this doesn't re-compress the files, but it proves it's the file names that are causing the problem)
If you're using the CodeIgniter zip library's function read_dir
, then that must be the culprit that's using absolute file paths. Try recursively walking the directory structure using PHP instead and use the add_data
function instead. That allows you to use any arbitrary path structure for each file, so you can write relative paths.
This can happen when files are zipped using the full directory path rather than the relative path. You can find an example of this problem here:
http://community.sharpdevelop.net/forums/p/1416/4532.aspx#4532
You may have to use another zip utility or write your own.
It might help to mention which version of windows you are using as well as the exact error you're getting. Is it windows 7 and you're trying to open files in a protected folder by chance or are you just trying to open it on the desktop?
I don't think this has anything to do with the the way the zip file was made but I could be wrong.
精彩评论