Work with ZIP-archives in PHP 5.2+

Starting with PHP 5.2 you can use useful library ZipArchive for easy working with ZIP archives.
(If your PHP version les 5.2 you’ll get error: class ziparchive not found)

Steps for easy working with ZipArchive
Init:

$zip = new ZipArchive;

Read ZIP archive:

$zip->open('{file_location_path}');

Create new ZIP archive (just add ZipArchive::CREATE):

$zip->open('{file_location_path}', ZipArchive::CREATE);

Example of extracting archive on your server:

$zip = new ZipArchive;
if ($zip->open('{file_location_path}') === true){
	$zip->extractTo('{file_location_extraction_path}');
	$zip->close();
}else{
	echo 'Archive file is not found';
}

Example of creating archive on your server:

$zip = new ZipArchive;
if ($zip->open('{file_location_creation_path}', ZipArchive::CREATE) === true){
	$zip->addFile('{file_name}', '{file_name_in_archive}');
	$zip->addFromString('{file_name_in_archive}', '{file_data}');
	$zip->addEmptyDir('{folder_name_in_archive}');
	$zip->close();
}else{
	echo 'Archive is not created';
}

Additional. If you catch error Class ‘ZipArchive’ not found .
Steps for fix for XAMPP on Windows.
1. Open http://pecl.php.net/package/zip
2. Select Available Releases in stable status and download php_zip_*.zip.
3. Extract and copy php_zip.dll to “:\xampp\php\ext”
4. Change php.ini. Add extension=php_zip.dll
5. Restart apache.