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

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

问题描述

目的是在运行sql转储脚本(来自PHP)后下载转储的backup.sql文件.通常,转储的 .sql 文件在服务器上输出(写入).然后,当我像 <a href="backup.sql">Download File</a> 那样创建指向该文件的 href 链接时,该文件在点击时在浏览器中打开,而不是被下载.

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 文件中.

Add the following lines to your .htaccess file.

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

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

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