PHP通过url下载远程图片到本地

function GrabImage($url,$filename) {
	if($url==""):return false;endif;

	ob_start();
	readfile($url);
	$img = ob_get_contents();
	ob_end_clean();
	$size = strlen($img);

	//"../../images/books/"为存储目录,$filename为文件名
	$fp2=@fopen("upfile/".$filename, "a");
	fwrite($fp2,$img);
	fclose($fp2);

	return $filename;
}
$filename=GrabImage("http://pic.111cn.net/enkj976.gif","11.jpg");

 

$men = new memcache();
    // you can replace localhost by memcached server ip addr and port no.
$men->connect('localhost','11211');
$men->add("mystr","this is a test",MEMCACHE_COMPRESSED,3600);
$str=$men->get("mystr");
echo $str; 

 

posted on 2015-05-27 21:02  小V_chen  阅读(756)  评论(0编辑  收藏  举报

导航