Best way to extract password protected zip files


A website of mine receives updates from the client in a zip file. I can open and process this fine but they are now insisting that the file is password protected, which is a bit of a problem. I can do something like the following:

echo shell_exec('unzip -P password');

but as the server is running IIS this throws up a permissions error. Apparently we need to “give the Internet Guest Account (a.k.a. IUSR_MachineName or simply IUSR) read and execute permission to the command shell program, cmd.exe.”

So, two questions:

  1. Are there any third-party apps/plugins/etc that will allow me to unzip password protected files? (I’m running PHP5 on a Windows server)
  2. What are the security risks in giving read and execute permissions to cmd.exe?

Any help would be gratefully received!


OK, i’m sort of getting somewhere. By using proc_open I can run unzip without cmd.exe being involved but I get the following error:

error:  cannot create C:/Home/.../www/zip/file.txt

Anyone got any ideas on that one? I’m thinking it might be a permissions issue on the folder maybe?

I’d look for a library that you can access from PHP rather than piping it through the shell. I know .NET has some native compression stuff you could call from PHP via .NET interop, but there is probably something more PHP specific that would be easier to wire in.


Do you mean a zip library? If so I’ve found a few but none of them will process password-protected archives, hence the reason I’ve had to resort to using the shell. I’ll have a look at the .net option though.