I'm creating some KML files on a web site and everything works well in all browsers except Firefox: the downloaded file is supposed to be someMap.kml, but Firefox just downloads this as 'someMap' without the '.kml'. Behavior in all other browsers is right, am I missing something?
This is my code:
<?php
$kml='<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmln开发者_高级运维s:atom="http://www.w3.org/2005/Atom">
<Document>
<Placemark>
<LookAt>
<longitude>-103.71866226196289</longitude>
<latitude>19.241143039165962</latitude>
<altitude>10000</altitude>
<heading>-0.00787786711370108</heading>
<tilt>0</tilt>
<range>20</range>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
</Placemark>
<NetworkLink>
<name>Posicion</name>
<Link>
<href>some URL</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>60</refreshInterval>
</Link>
</NetworkLink>
</Document>
</kml>';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/vnd.google-earth.kml+xml kml; charset=ISO-8859-1");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($kml));
header("Pragma: no-cache");
header("Content-disposition: attachment; filename=someMap.kml");
echo $kml
?>
Remove all the other headers apart from Content-disposition and Content-Type.
You have the quote marks a little of on the Content-Disposition header as is, try wrapping the file name in quotes. Also, the content type should not have the charset set (at least I think not) Finally. you should remove any white space before the headers.
Try this.
// rest of the file...
</kml>';
header('Content-Type: application/vnd.google-earth.kml+xml kml');
header('Content-Disposition: attachment; filename="someMap.kml"');
echo $kml;
?>
精彩评论