Ok here is a problem that has been annoying me for a while. Just in a personal project that im working on, and i finally sat down and figured out how to do it via PHP.

Now this is probably easy and known for most people but if you don’t know how to do it keep reading…
The challenge was, extract multiple files from a passworded zip that’s attached to an email. I know sounds easy, but what if you want the server to do it for you? Now this is running on a hostgator account with default settings and probably execute allowance as well.
After a few trial and errors the following code worked for me, this is the long winded version of it, you can shorten it if you like…:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php $zip_name = "file.zip"; $pathtozipfle = "upload-path"; $destinationdir = "upload-path"; $passw = "password"; $extract_command = "unzip -P $passw $pathtozipfle/$zip_name -d $pathtozipfle/"; echo "Running: $extract_command"; // note probably better and safer to not echo this line as it will reveal the password. But as this is very insecure anyway it probably does not matter too much. echo "<br><br>"; echo system($extract_command); echo "<br><br>"; ?> |
Anyway this extracts file files with no major issues. If you want it to run without returning any data to the screen just run:
1 2 3 | <?php system($extract_command); ?> |
If you would like to see what other options are available, and your version of unzip you can run:
1 2 3 | <?php echo system("unzip -Z"); ?> |




kruxor on August 9th, 2010
Post Tags