PHP强制下载文件方法浅析

原创
2016-07-25 08:54:49 708浏览
  1. $filename = "test.txt";
  2. header ("Content-Type: application/force-download");
  3. header ('Content-Disposition: attachment;filename="'.$filename.'"');
  4. readfile ($filename);
复制代码

如此便可以实现文件直接下载而非打开。

原理分析: 1,header ("Content-Type: application/force-download"); //强制下载; 2,header ('Content-Disposition: attachment;filename="'.$filename.'"'); //实现文件下载.最后readfile($filename)读取文件进行下载.



声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。