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"); ?> (编辑:银川站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |