Showing posts with label PHP Extract Zip File. Show all posts
Showing posts with label PHP Extract Zip File. Show all posts

Monday, 23 February 2015

Unzip files with PHP

The following function takes two parameters: The .zip file to unzip, and the destination directory.
<?php
function unzip_file($file, $destination){ 
// create object 
$zip = new ZipArchive() ; 
// open archive 
if ($zip->open($file) !== TRUE) { 
die ('Could not open archive'); 
}
 // extract contents to destination directory 
$zip->extractTo($destination); 
// close archive $zip->close();
 echo 'Archive extracted to directory'; 
}
?>