raw snippet

Google Earth uses a XML based file format for data exports, named with KML extension, which can be created easily with PHP. However, when icons and other data must be packed together to a KMZ file, the following snippet can create the ZIP-File, with KMZ extension using the PHP zip extension:

// Copyright Robert Eisele 2017
$kml = <<<KML
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <name>XARG.org Snippet</name>
    <Style id="msn">
        <name>This is a name</name>
            <description>This is a description.</description>

$zip = new ZipArchive();
if ($zip->open('GoogleEarth.kmz', ZIPARCHIVE::CREATE)) {

    foreach (glob('icons/*') as $file) {
        $zip->addFile($file, 'files/' . basename($file));
    $zip->addFromString('doc.kml', $kml);