这里的教程是使用php ... http://code.google.com/apis/kml/articles/phpmysqlkml.html
从数据库生成kml的一个很好的资源但是我的问题是,当脚本运行时,生成的文件保存为.php,而不是.kml。我怎样才能使它像.kml一样?以下是具体代码。谢谢!
<?php
$kml = array('<?xml version="1.0" encoding="UTF-8"?>');
$kml[] = '<kml xmlns="http://www.opengis.net/kml/2.2">';
$kml[] = '<Document>';
$kml[] = '</Document>';
$kml[] = '</kml>';
$kmlOutput = join("\n", $kml);
header('Content-type: application/vnd.google-earth.kml+xml');
echo $kmlOutput;
?>
答案 0 :(得分:8)
您正在访问以生成文件的文件可能具有php扩展名,因此浏览器认为这是您正在下载的内容的扩展名
确保在标题中设置扩展名为
的文件名header('Content-Disposition: attachment; filename="file.kml"');
答案 1 :(得分:3)
header('Content-type: application/vnd.google-earth.kml+xml');
header('Content-disposition: attachment; filename="myfilename.kml"');