php文件下载实现方法
第一行代码是强制下载,第二行代码是给下载的内容指定一个名字,第三行代码是把下载的内容读进文件中,提示用户保存一个生成的 pdf 文件,content-disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框,代码如下:
<?php header( "content-type: application/force-download" ); header( "content-disposition: attachment; filename=ins.jpg" ); readfile( "imgs/test_zoom.jpg" ); ?>header() 函数向客户端发送原始的 http 报头,认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数,在 php 4 以及更高的版本中,您可以使用输出缓存来解决此问题,代码如下:
header(string,replace,http_response_code)
其它用法,代码如下:
<?php // date in the past header( "expires: mon, 26 jul 1997 05:00:00 gmt" ); header( "cache-control: no-cache" ); header( "pragma: no-cache" ); ?>查看更多关于php文件下载实现方法 - php上传下载的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did29345