
php保存远程图片到本地
functionGrabImage($url,$filename=""){if($url==""):returnfalse;endif;if($filename=="")...
function GrabImage($url,$filename="") {
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dMYHis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
$img=GrabImage("http://www.baidu.com/img/baidu_logo.gif",""); //地址
if($img):echo '<pre><img src="'.$img.'"></pre>';else:echo "false";endif;
PHP的还有别的办法吗?最好越简单的越好.. 展开
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dMYHis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
$img=GrabImage("http://www.baidu.com/img/baidu_logo.gif",""); //地址
if($img):echo '<pre><img src="'.$img.'"></pre>';else:echo "false";endif;
PHP的还有别的办法吗?最好越简单的越好.. 展开
3个回答
展开全部
<?php
$img = file_get_contents('http://www.baidu.com/img/baidu_logo.gif');
file_put_contents('1.gif',$img);
echo '<img src="1.gif">';
?>
$img = file_get_contents('http://www.baidu.com/img/baidu_logo.gif');
file_put_contents('1.gif',$img);
echo '<img src="1.gif">';
?>
展开全部
$img = file_get_contents('http://www.91cici.com/images/logo.gif');
file_put_contents('test.gif',$img);
file_put_contents('test.gif',$img);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |