Advertisement
shishir123

Unzip a file in php

Aug 6th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. function unzip_file($file, $destination){
  2.     // create object
  3.     $zip = new ZipArchive() ;
  4.     // open archive
  5.     if ($zip->open($file) !== TRUE) {
  6.         return false;
  7.     }
  8.     // extract contents to destination directory
  9.     $zip->extractTo($destination);
  10.     // close archive
  11.     $zip->close();
  12.         return true;
  13. }
  14. How to use it.
  15.  
  16. if(unzip_file($file["name"],'uploads/')){
  17. echo 'zip archive extracted successfully';
  18. }else{
  19.   echo 'zip archive extraction failed';
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement