php下载图片

AndyYang| 阅读:809 发表时间:2012-05-22 15:01:00 php
摘要:一直不知道怎么让自己网站的图片提供下载功能。刚开始以为是file_get_contents();file_put_contents();就能搞定,结果发现只是保存在服务器而已

一直不知道怎么让自己网站的图片提供下载功能。
刚开始以为是

file_get_contents();
file_put_contents();

就能搞定,结果发现只是保存在服务器而已。
后面在网上搜了下,结果发现可以这样:

$imgName = '../'.$imgsrc;     //(可以是路径,也可是网址)
header('Content-type: application/png'); 
header('Content-Disposition: attachment; filename="ceshi.png"'); //这里的filename是指定下载后的文件名称 
readfile($imgName); 

原来so easy!

本文为AndyYang原创,转载请注明出处!
如果您觉得好,可以打赏作者:
如果您觉得累了,是否想看点美女养养眼:猛戳>>朋友帮
如果您觉得皮了,是否想来点神吐槽:猛戳>>iPhone查询中

已有0条评论

昵称:
邮箱:

  • 最新评论

iPhone查询中 - bbs.ipcxz.com 朋友帮 - www.pengyb.cn iPhone查询中 - bbs.ipcxz.com
反馈
微信订阅号