下载 KML 文件而不是在浏览器中查看

发布于 2024-10-17 00:55:49 字数 412 浏览 3 评论 0原文

我正在开发一个创建 KML 文件的项目(就像 XML 文件,但用于 Google 地球)。有趣的是,当我链接到本地​​计算机上运行 XAMPP 的新创建的文件时,该文件会自动下载,但是当我将其移动到我的 Web 服务器(Linux、EC2 上的 Fedora 8)时,该链接仅加载 KML 文件在浏览器中就像一个 HTML 文件一样。

如何强制它下载文件而不是在浏览器中查看文件?

以下是如何使用 PHP 显示链接,

echo "<a href='$currentTime.kml'><img heigth=\"15px\" width=\"13px\" src=\"images/KML_Icon.gif\" /> Download</a>";

任何建议都会有帮助,谢谢!

I am working on a project which creates a KML File (just like an XML file, but used for Google Earth). Whats interesting is when I link to the newly created file, on my local machine, running XAMPP, the file is downloaded automatically, however when I move it to my web server (Linux, Fedora 8 on EC2) the link just loads the KML file in the browser as if it was an HTML file.

How can I force it to download the file instead of viewing it in the browser?

Here's how to link is displayed with PHP,

echo "<a href='$currentTime.kml'><img heigth=\"15px\" width=\"13px\" src=\"images/KML_Icon.gif\" /> Download</a>";

Any advice would help, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虐人心 2024-10-24 00:55:49

您需要做的是指定标头,以便浏览器知道如何处理您发送的信息。因此,在向浏览器发送任何内容之前,您需要指定标头。

如果您要链接到特定文件,那么您将必须创建一个小“下载管理器”来为您执行此操作。

<?
  header('Content-disposition: attachment; filename=the-name-you-want-them-to-see-in-their-download.pdf');
  header('Content-type: text/xml'); //Since KML files are based on XML this is probably the best Content type to send to the user.
  readfile('the-file-you-want-to-present')
?>

应该可以做到这一点。

What you need to do is to specify the headers so the Browser knows what to do with the information that you are sending. So before you send anything to the browser you will need to specify the headers.

If you are linking to a specific file, then you will have to create a little "download manager" that will do this for you.

<?
  header('Content-disposition: attachment; filename=the-name-you-want-them-to-see-in-their-download.pdf');
  header('Content-type: text/xml'); //Since KML files are based on XML this is probably the best Content type to send to the user.
  readfile('the-file-you-want-to-present')
?>

That should do it.

陌路终见情 2024-10-24 00:55:49

感谢你们的意见,但奥德有关于哑剧类型的答案。

在服务器上有一个名为 mime.types 的文件,它不包含 KML 文件的 mime 类型,我添加了

application/vnd.google-earth.kml+xml

它现在下载该文件而不是在浏览器中加载它,顺便说一下,一旦您需要重新启动 apache已做出更改。

Thank you for your guys' input, but Oded had the answer regarding the mime types.

On the server there's a file called mime.types which didn't contain the mime type for a KML file, I added in

application/vnd.google-earth.kml+xml

And it now downloads the file instead of loading it in the browser, by the way apache needs to be restarted once you have made the changes.

此刻的回忆 2024-10-24 00:55:49

我很久以前就有过这个,我使用了类似的方法:

http:// /webdesign.about.com/od/php/ht/force_download.htm

I had this a long while ago, I used a method similar to this:

http://webdesign.about.com/od/php/ht/force_download.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文