如何创建可下载链接到文本文件? [英] How to create downloadable link to text file?

查看:203
本文介绍了如何创建可下载链接到文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目的是在运行sql转储脚本(从PHP)之后下载转储的 backup.sql 文件。通常,在服务器上输出(写入)转储的 .sql 文件。然后,当我将一个href链接到< a href =backup.sql>下载文件< / a> 时,该文件在浏览器中打开点击,而不是下载。

The purpose is to download the dumped backup.sql file after running the sql dumping script (from PHP). Normally, the dumped .sql file is outputted (written) on the server. Then when i make a href link to that file like <a href="backup.sql">Download File</a>, the file is opening inside the browser on clicking, instead of being downloading.


  • 我只想做一个简单的 HREF LINK (到这样一个简单的左击
  • i just want to make a simple HREF LINK (to such a text file) which show up with "Save as.." dialog on simple Left Click.

如何才能完成?

推荐答案

将以下行添加到中。 htaccess 文件。

<Files "backup.sql">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</Files>

这篇关于如何创建可下载链接到文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆