<?php function lanye_httpcode($url){ $ch = curl_init(); $timeout = 3; curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch,CURLOPT_URL,$url); curl_exec($ch); return $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE); curl_close($ch); } function lanye_getavatar($email, $s = 40, $d = 'monsterid', $g = 'g') { $hash = md5($email); $avatar = "http://cn.gravatar.com/avatar/$hash?s=$s&d=$d&r=$g"; return $avatar; } function lanye_cacheavatar($mail,$size){ $hash = md5(strtolower($mail)); $error_url = 'http://cn.gravatar.com/avatar/'.$hash.'?d=404'; $cache_path = TEMPLATE_PATH.'cache'; if(!file_exists($cache_path)){mkdir($cache_path,0700);} $avatar_http_url = TEMPLATE_URL.'cache/'.$hash.'.jpg'; $avatar_path_url = $cache_path."/".$hash.'.jpg'; $cache_time = 24*3600*30; if(!file_exists($avatar_path_url) || (time()-filemtime($avatar_path_url)) > $cache_time){ if(lanye_httpcode($error_url)==200){$newavatar = lanye_getavatar($mail,$size);copy($newavatar,$avatar_path_url);} else{copy($cache_path.'/default.jpg',$avatar_path_url);} } return $avatar_http_url; }?> 调用例子: <?php echo lanye_cacheavatar(邮箱地址,头像大小);?>
免责声明:
本页网址:点击复制分享给朋友吧!
本站分享的一切内容资源如若没有备注,均为蓝叶原创,如需转载请注明出处;如有侵权请与我们联系处理。敬请谅解!