Fun with PECL Zip 1.6 – Installation


With PECL Zip you can read, add, delete, set and read archive comment, it’s a very useful package for searching and managing Zipped archive kind of data.
let’s begin with the installation
fire up your PECL installer to install Zip; you’ll see some information verbosed while installed PECL Zip like the following

  1. wget http://pecl.php.net/get/zip &&  tar -zxvf zip && cd zip-1.6.0/ && phpize5 && sudo ./configure && sudo  make && sudo make install

During the installation you will be flooded with verbosed information ; it’s useful to watch and try to understand what’s going behind the scene; keep your eye on the verbose to see if any error popup like missing library or permission problem, if the installation went fine; at the end you will see

  1. Installing shared extensions:     /usr/lib/php5/20050922/

Now let’s edit php.ini

  1. sudo vim /etc/php5/apache2/php.ini

and add

  1. extension=zip.so

now you will only need to restart apache to get the new extension loaded

  1. sudo /etc/init.d/apache2 restart

Now ZIP extension are installed so let’s explore the examples directory where you will see PHP code example of how to use ZIP extension

First let’s see what methods ZIP class have

  1. < ?php
  2. $Zip = New ZipArchive();
  3. print '<pre>'.print_r(get_class_methods($Zip)).'';

This will output

  1. Array ( 
  2. [0] => open                      [1] => close 
  3. [2] => addFromString         [3] => addFile 
  4. [4] => renameIndex           [5] => renameName 
  5. [6] => setArchiveComment [7] => getArchiveComment 
  6. [8] => setCommentIndex    [9] => setCommentName 
  7. [10] => getCommentIndex  [11] => getCommentName 
  8. [12] => deleteIndex          [13] => deleteName 
  9. [14] => statName             [15] => statIndex 
  10. [16] => locateName          [17] => getNameIndex 
  11. [18] => unchangeArchive   [19] => unchangeAll 
  12. [20] => unchangeIndex      [21] => unchangeName 
  13. [22] => extractTo             [23] => getFromName 
  14. [24] => getFromIndex        [25] => getStream )

Most of methods and functions are being used in the example folder of Zip extention

  1. comment.php  create.php  dir.php  extractAll.php  extract.php  fopen.php  get_set_comments.php  odt.php  oldapi.php  test1.zip  test_with_comment.zip  test.zip  too.php

Enjoy

Resources

  1. PECL Zip page
  2. Zip documentation at PHP.net
  3. PECL Zip – new features announcement

Tags: , ,

2 Responses to “Fun with PECL Zip 1.6 – Installation”

  1. Pierre Says:

    You don’t need zzlib to install pecl/zip, neither with the upcoming PHP 5.2.0. The extension does not use any external library :)

  2. Jad Says:

    Thanks for correction dude, I must were drunk while compiling it :D

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>