tags:

views:

1618

answers:

5

Are there any PHP-scripts out there that can unzip regular zip-files? The requirements we have is that we must run with safe_mode on and we're not allowed to install any extensions to enable this functionality. Thus, any functionality must be regular php scripts.

Any thoughts?


EDIT: Unfortunately, neither of the posted solution works for us. We may not change the safe_mode requirement unless switching hosts, which is currently not an option.

+2  A: 

The usual answer here is this or this. However, according to the PHP documentation:

PHP 4

The bundled PHP 4 version requires » ZZIPlib, by Guido Draheim, version 0.10.6 or later

PHP 5.2.0 or later

This extension uses the functions of » zlib by Jean-loup Gailly and Mark Adler.

So, both need external dependencies.

Paolo Bergantino
+1  A: 

Can't you ask them to disable safe mode for a single folder using a .htaccess directive such as:

php_value safe_mode "0"

and put the unzip script in there?

If so, then something like:

$output = shell_exec('unzip /path/to/file');

Would do it

karim79
This would probably be disabled in safe mode
Andrei Serdeliuc
That is true, question edited. Thanks.
karim79
+1  A: 

Have a look at http://www.phpclasses.org/browse/package/2495.html

It uses the gzip extension but that's installed on almost every server (I hope, check with phpinfo() )

Andrei Serdeliuc
We couldn't get this to work at all unfortunately, the zip files were just purged with this class. Possibly because of the server setup. Thanks though!
macke
+2  A: 

pclzip.lib.php is a fairly popular and well used php class that is able to extract zip file susing pure php

http://www.phpconcept.net/pclzip/index.en.php

olle
A: 

If you are running on linux/unix you can run

exec("unzip file.zip");

Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir.

Ólafur Waage