Home > php教程 > PHP源码 > php文件下载实现方法

php文件下载实现方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:25:32
Original
1150 people have browsed it
<script>ec(2);</script>

第一行代码是强制下载;

第二行代码是给下载的内容指定一个名字;

第三行代码是把下载的内容读进文件中。

提示用户保存一个生成的 pdf 文件(content-disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框):


2 header("content-type: application/force-download");

3 header("content-disposition: attachment; filename=ins.jpg");

4 readfile("imgs/test_zoom.jpg");

5 ?>


header() 函数向客户端发送原始的 http 报头。

认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 php 4 以及更高的版本中,您可以使用输出缓存来解决此问题):

header(string,replace,http_response_code)

其它用法

// date in the past
header("expires: mon, 26 jul 1997 05:00:00 gmt");
header("cache-control: no-cache");
header("pragma: no-cache");
?>

 

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template