PHP, WEB

Create a zip file using PHP and ZipArchive class

You can create zip archives in PHP using ZipArchive class.

public function createZipArchive($files, $archive, $overwrite) {
		$zip = new ZipArchive ();
		if ($overwrite)
			$flags = ZipArchive::CREATE | ZipArchive::OVERWRITE;
		else
			$flags = ZipArchive::CREATE;
		if (($zip->open ( $archive, $flags )) !== true) {
			return false;
		} else {
			foreach ( $files as $file ) {
				if (file_exists ( $file ))
					$zip->addFile ( $file, basename ( $file ) );
			}
			$zip->close ();
			return true;
		}
	}