Posted By

icecreamboyy on 02/24/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

geek4evr


Php Unzip


 / Published in: PHP
 

  1. /***************************************************
  2. * Function to unzip a file zipped with PHP's ZipArchive.
  3. * Parameters Expected:
  4. * $zip_file: The zip file (with path) we wish to unzip
  5. * $directory: Where we want the contents unzipped to
  6. **************************************************/
  7. function unZipArchive($zip_file,$directory)
  8. {
  9. //create a new ZipArchive class
  10. $zip_archve = new ZipArchive();
  11.  
  12. //attempt to open the archive file
  13. $results = $zip_archive->open($zip_file);
  14.  
  15. switch($results)
  16. {
  17. case TRUE:
  18. //format the directory properly
  19. $directory = str_replace("\\","/",$directory);
  20. //extract the files
  21. $zip_arvhive->extractTo($directory);
  22. //close the ZipArchive
  23. $zip_archive->close();
  24. //Return True
  25. return true;
  26. break;
  27. case FALSE:
  28. echo "Failed opening archive file. Error Code: " . $results;
  29. return false;
  30. }
  31. }

Report this snippet  

You need to login to post a comment.