Author: ApPHP Language: php
Description: This code allows you to Unzip a ZIP file with PHP. Timestamp: 2017-10-02 19:22:04 +0000
View raw paste Reply
  1. <?php          
  2. function unzip($location,$new_location){
  3.     if(exec("unzip $location",$arr)){
  4.         mkdir($new_location);
  5.         for($i = 1;$i< count($arr);$i++){
  6.             $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
  7.                     copy($location."/".$file,$new_location."/".$file);
  8.                     unlink($location."/".$file);
  9.             }
  10.         return true;
  11.     }
  12.     return false;      
  13. }
  14.  
  15. // usage of this code
  16.  
  17. if(unzip('ziped_files/test.zip','unziped_files/newfile')){
  18.     echo 'Successfully unzipped!';
  19. }else{
  20.     echo 'Error while processing your file!';
  21. }
  22. ?>
View raw paste Reply