我在网站上创建了一些KML文件,除了Firefox之外,所有浏览器都能正常运行:下载的文件应该是someMap.kml,但Firefox只是将其下载为“someMap”,而不是“.kml” 。所有其他浏览器中的行为都是对的,我错过了什么吗?
这是我的代码:
<?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" xmlns: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
?>
答案 0 :(得分:0)
除了Content-disposition和Content-Type之外,删除所有其他标题。
您可以在Content-Disposition标题上使用引号标记,尝试将文件名包装在引号中。此外,内容类型不应该有charset集(至少我认为不是)最后。你应该删除标题前的任何空格。
试试这个。
// rest of the file...
</kml>';
header('Content-Type: application/vnd.google-earth.kml+xml kml');
header('Content-Disposition: attachment; filename="someMap.kml"');
echo $kml;
?>