There's a ton of really good libraries for handling the zipping and unzipping of files. The following solution is super-simple in nature and uses PHP's ZIP extension that "enables you to transparently read or write ZIP compressed archives and the files inside them". The same class can be used to zip files and perform a number of other operations.
1
<?php
2
/*
3
Unzip a file with PHP
4
http://www.beliefmedia.com/code/php-snippets/unzip-file-php
5
*/
6
7
function beliefmedia_unzip_file($file, $location = 'extracted/') {
8
$zip = new ZipArchive;
9
$result = $zip->open($file);
10
11
if ($result === true) {
12
$zip->extractTo($location);
13
$zip->close();
14
return true;
15
} else {
16
return false;
17
}
18
}
19
20
/* Usage */
21
echo beliefmedia_unzip_file($file = 'some-zip-file.zip') ? 'Successful' : 'Error';
To zip a file, look at the ZipArchive::addFile documentation.