[英]how to download a .txt file by clicking using PHP
I have a .TXT file on my xampp server, if a user clicks on a link it should download, but instead it opens up in my browser window. 我的xampp服务器上有一个.TXT文件,如果用户单击它应该下载的链接,但是它将在我的浏览器窗口中打开。
My code looks as follows: 我的代码如下所示:
<a href="<?php echo base_url();?>assets/task/start/<?php echo $files->task_verify_file;?>"><?php echo $files->task_verify_file;?></a>
any one solve the problem thanks 任何人都可以解决问题,谢谢
I did it like this: 我这样做是这样的:
if (file_exists ($file)) {
header("Content-Type: text/plain; charset=utf-8");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$filename);
readfile($file);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.