PhpConcept

Developers Tools

  • Increase font size
  • Default font size
  • Decrease font size
Home PclZip F.A.Q.

PclZip FAQ

Print PDF

While creating an archive with PclZip, the script terminates with an empty created zip archive, why ?

I can not open with WinZip a zip archive created by PclZip !

While extracting (creating) a zip with PclZip the PHP script hang before the end of the script, without any error message ...

While extracting a zip with PclZip I see nothing (no extracted file, no error) ...

How can I create a zip file with the current directory and all its content recursively ?

Q1 : While creating an archive with PclZip, the script terminates with an empty created zip archive, why ?

The behavior was encounter while the zlib extension is not enabled with the PHP installation. PclZip uses the compression functions from the zlib. In next releases of PclZip (1.1+) a systematic control of the zlib presence will be done.

Q2 : I can not open with WinZip a zip archive created by PclZip !

WinZip 6.0 (and earlier) is not able to open zip archives created by PclZip. However last version of WinZip (v8.0) is working correctly with PclZip generated archives. Please note also that archives created by PclZip can be read by WinZip 6.0.

Q3 : While extracting (creating) a zip with PclZip the PHP script hang before the end of the script, without any error message ...

PclZip depend on two PHP configuration parameters for its performance :
PclZip is using in memory compression/decompression of files in order to limit the usage of temporary files. This technic depends on the memory allocated to a PHP thread by the hosting server. If you are zipping a very large file, a large amount of memory will be needed, if you are zipping lots of small files it should be ok. The allocated memory for PHP can be configured by changing the "memory_limit" parameter in the php.ini file (see for more details). The default value is 8M.
When you extract or create a very fat zip (big zip or zip with many small files), PHP needs lots of time to process all the archive. The execution time allocated to a PHP thread is configured in the php.ini file (see for more details). The default is 30 secondes.

Q4 : While extracting a zip with PclZip I see nothing (no extracted file, no error) ...

PclZip support an error mechanism described in the user manual (see ). You must check for error after calling a PclZip function.

However the initial implementation of PclZip support a kind of minor "error recovery" mecanism. The idea is that the script will stop only if it can not recover from an error. When extracting an archive if one file can not be extracted, the script does not stop, but resume the action and tries to extract the other files. In order to check which file was extracted or not, and why some files were not extracted (bad access rights, already existing files, directories with same names, ...) you need to study the resulting array of the extract action.
If you want to see how it works, run this sample code :

    require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if ((
$v_result_list = $archive->extract()) == 0) {
die(
"Error : ".$archive->errorInfo(true));
}
echo
"<pre>";
var_dump($v_result_list);
echo
"</pre>";

Since PclZip release 2.2, you have the ability to stop the extraction at the first "minor" error. To do that you need to use the optional parameter PCLZIP_OPT_STOP_ON_ERROR :

    require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if ((
$v_result_list = $archive->extract(PCLZIP_OPT_STOP_ON_ERROR)) == 0) {
die(
"Error : ".$archive->errorInfo(true));
}
echo
"<pre>";
var_dump($v_result_list);
echo
"</pre>";

Q5 : How can I create a zip file with the current directory and all its content recursively ?

PclZip does not directly support the add of folder "./". To do this you will have to use a trick :

    require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
$v_dir = getcwd(); // or dirname(__FILE__);
$v_remove = $v_dir;
// To support windows and the C: root you need to add the
// following 3 lines, should be ignored on linux
if (substr($v_dir, 1,1) == ':') {
$v_remove = substr($v_dir, 2);
}
$v_list = $archive->create($v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove);
if (
$v_list == 0) {
die(
"Error : ".$archive->errorInfo(true));
}

Last Updated on Saturday, 19 December 2009 12:48