How to extract .zip archive (PHP)

A function that allows you to extract files from a zip archive to a specified folder:


function extractZip($filePath, $extractTo){
$zip = new ZipArchive();
$result = $zip->open($filePath);
if ($result === TRUE) {
$zip->extractTo($extractTo);
$zip->close();
}
return $result;
}

$file = 'myfile.zip'; // change to your file path
$folder = 'myfolder'; // change to your folder path

extractZip($file, $folder);

Note: you need a zlib library for this code to work

 

Comments

No comments yet, you can leave yours: