下载 KML 文件而不是在浏览器中查看
我正在开发一个创建 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要做的是指定标头,以便浏览器知道如何处理您发送的信息。因此,在向浏览器发送任何内容之前,您需要指定标头。
如果您要链接到特定文件,那么您将必须创建一个小“下载管理器”来为您执行此操作。
应该可以做到这一点。
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.
That should do it.
感谢你们的意见,但奥德有关于哑剧类型的答案。
在服务器上有一个名为 mime.types 的文件,它不包含 KML 文件的 mime 类型,我添加了
它现在下载该文件而不是在浏览器中加载它,顺便说一下,一旦您需要重新启动 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
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.
我很久以前就有过这个,我使用了类似的方法:
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