Unzip file using PHP


/ Published in: PHP
Save to your folder(s)

A few days ago i was looking for a script witch one will help me to unzip a file using PHP . There is 2 different ways to do it.One just execute a commend to unzip the file in the shell using PHP and another one is using library functions


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. // create object
  4. $zip = new ZipArchive() ;
  5.  
  6. // open archive
  7. if ($zip->open(’archive. zip’) !== TRUE) {
  8. die (’Could not open archive’);
  9. }
  10.  
  11. // extract contents to destination directory
  12. $zip->extractTo(’/ tmp/extracted/ ‘);
  13.  
  14. // close archive
  15. // print success message
  16. $zip->close();
  17. echo ‘Archive extracted to directory’;
  18.  
  19. ?>

URL: http://ranacse05.wordpress.com/2008/03/20/unzip-file-using-php/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.