牛客网刷题-04 之一个图片url访问后直接下载怎样实现

一个图片url访问后直接下载怎样实现

方法一:
i m g U r l = ′ h t t p : / / o f f l i n t a b . f i r e f o x c h i n a . c n / s t a t i c / i m g / s e a r c h / b a i d u w e b . p n g ′ ; o b c l e a n ( ) ; o b s t a r t ( ) ; r e a d f i l e ( imgUrl = 'http://offlintab.firefoxchina.cn/static/img/search/baidu_web.png'; ob_clean(); ob_start(); readfile( imgUrl=http://offlintab.firefoxchina.cn/static/img/search/baiduweb.png;obclean();obstart();readfile(imgUrl);
$img = ob_get_contents();

ob_end_clean();

$imgName = 'test.jpg';    //自定义图片名称

$savePath = './test';          //自定图片存放路径
$fp = fopen($savePath.$imgName,'w');
fwrite($fp,$img);

fclose($fp);

方法二:


Click Me

其他方法:设置 response header content-type

你可能感兴趣的:(刷题)