PDA

View Full Version : Unzipping files



Chimichanga15
08-31-2003, 11:51 AM
I want to upload a zipped (*.zip) file to the server, then have the php script that "receives" the file and puts it on the server to unzip it. I got the first part to work: the file uploads fine. Now I need to get it to unzip. I found this (http://si.php.net:8888/manual/en/ref.zip.php), and have tried to follow these instructions. It hasn't worked, and it looks like I need to install the ZZIPLib library (http://zziplib.sourceforge.net/). How do I install this? Also, what version of PHP is on the WestHost servers? Thanks.

FZ
08-31-2003, 04:18 PM
I believe WestHost is using PHP 4.3.1. It could be different on your server. You can always check by making a file (e.g. test.php) with the following code in it, uploading it and then viewing it in your browser:


<? phpinfo(); ?>

If you are not familiar with SSH then installing a library (or installing anything for that matter) can be an extremely daunting task. If you aren't on WestHost 2.0, then you shouldn't even bother because it probably won't allow you. I'd recommend another way...

I've never tried doing what you want (not with user input anyway), but you can use the unzip (shell) program available on the server with your PHP script. Have a look at this code (works for me):


<?
exec('unzip images.zip', $outputlines);
echo 'Script returned the following: ';
foreach ($outputlines as $outputline) echo $outputline;
?>

The above unzips images.zip in the same directory and then sends the output of the command to the browser. Of course, that is oversimplified and you should never allow user input to control something like that, so you should take a look at this: http://www.php.net/manual/en/function.exec.php and incorporate some error checking, etc. in your script.

Chimichanga15
09-01-2003, 10:21 AM
It works beautifully. I had to do a little bit of string manipulation to get the file name from the full path to just the name of the file, but it works. Thanks![/quote]

FZ
09-01-2003, 11:11 AM
My pleasure... Glad I could help :) If you feel adventurous, you should give installing that module a go (once you are moved to a WestHost 2.0 server, of course) - it will probably give you a lot more flexibility and security.