【转】php让图片弹出下载框的方法

在做图片下载站时,常常需要给用户下载图片,但图片浏览器是直接可以打开的.怎么办呢,有没有什么方法可以让图片类型的文件弹出下载框下载呢, phperz.com

当然是有的,php的header函数就可以提供这种方法 php程序员之家

以下代码你可以copy下来测式一下 www.phperz.com

 

以下为引用的内容:
<?php
$filename = "123.jpg";//图片地址,可以绝对地址也可以相对地址
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'.$filename.'"');
$img = file_get_contents($filename); 
echo $img;
?>

www.phperz.com

 

效果如下: www.phperz.com

www.phperz.com

关键点在于 php程序员之家

header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'.$filename.'"');

phperz~com

 

 

 

 

这二行代码,让告诉浏览器强制下载文件

 

转载至:phpzer

 
 
posted @ 2017-09-12 11:15  殍地  阅读(1116)  评论(0编辑  收藏  举报