discuz通过用户名调头像
<?php/*[UCenter](C)2001-2099ComsenzInc.ThisisNOTafreeware,useissubjecttolicenseterms$Id:avatar.php11442013-01-3106:47:43Zzhangjie$*/include'./config.inc.php';include'../uc_client/client.php';error_reporting(0);_get_script_url();define('UC_API',strtolower(($_SERVER['HTTPS']=='on'?'https':'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/'))));$username=isset($_GET['username'])?$_GET['username']:'';//$uid=isset($_GET['uid'])?$_GET['uid']:0;$size=isset($_GET['size'])?$_GET['size']:'';$random=isset($_GET['random'])?$_GET['random']:'';$type=isset($_GET['type'])?$_GET['type']:'';$check=isset($_GET['check_file_exists'])?$_GET['check_file_exists']:'';//$avatar='./data/avatar/'.get_avatar($uid,$size,$type);$avatar='./data/avatar/'.get_avatar($username,$size,$type);if(file_exists(dirname(__FILE__).'/'.$avatar)){if($check){echo1;exit;}$random=!empty($random)?rand(1000,9999):'';$avatar_url=empty($random)?$avatar:$avatar.'?random='.$random;}else{if($check){echo0;exit;}$size=in_array($size,array('big','middle','small'))?$size:'middle';$avatar_url='p_w_picpaths/noavatar_'.$size.'.gif';}if(empty($random)){header("HTTP/1.1301MovedPermanently");header("Last-Modified:".date('r'));header("Expires:".date('r',time()+86400));}header('Location:'.UC_API.'/'.$avatar_url);exit;//functionget_avatar($uid,$size='middle',$type=''){functionget_avatar($username,$size='middle',$type=''){if($data=uc_get_user($username)){list($uid,$username,$email)=$data;$my_var=$uid;}else{echo'用户不存在';}$uid=$my_var;$size=in_array($size,array('big','middle','small'))?$size:'middle';$uid=abs(intval($uid));$uid=sprintf("%09d",$uid);$dir1=substr($uid,0,3);$dir2=substr($uid,3,2);$dir3=substr($uid,5,2);$typeadd=$type=='real'?'_real':'';return$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid,-2).$typeadd."_avatar_$size.jpg";}function_get_script_url(){$scriptName=basename($_SERVER['SCRIPT_FILENAME']);if(basename($_SERVER['SCRIPT_NAME'])===$scriptName){$_SERVER['PHP_SELF']=$_SERVER['SCRIPT_NAME'];}elseif(basename($_SERVER['PHP_SELF'])===$scriptName){$_SERVER['PHP_SELF']=$_SERVER['PHP_SELF'];}elseif(isset($_SERVER['ORIG_SCRIPT_NAME'])&&basename($_SERVER['ORIG_SCRIPT_NAME'])===$scriptName){$_SERVER['PHP_SELF']=$_SERVER['ORIG_SCRIPT_NAME'];}elseif(($pos=strpos($_SERVER['PHP_SELF'],'/'.$scriptName))!==false){$_SERVER['PHP_SELF']=substr($_SERVER['SCRIPT_NAME'],0,$pos).'/'.$scriptName;}elseif(isset($_SERVER['DOCUMENT_ROOT'])&&strpos($_SERVER['SCRIPT_FILENAME'],$_SERVER['DOCUMENT_ROOT'])===0){$_SERVER['PHP_SELF']=str_replace('\\','/',str_replace($_SERVER['DOCUMENT_ROOT'],'',$_SERVER['SCRIPT_FILENAME']));$_SERVER['PHP_SELF'][0]!='/'&&$_SERVER['PHP_SELF']='/'.$_SERVER['PHP_SELF'];}else{returnfalse;}return$_SERVER['PHP_SELF'];}?>
uc_server目录下新增加avatar2.php,内容如上
<?phpdefine('UC_CONNECT','mysql');define('UC_DBHOST','localhost');define('UC_DBUSER','root');define('UC_DBPW','xxx533530');define('UC_DBNAME','ultrax');define('UC_DBCHARSET','utf8');define('UC_DBTABLEPRE','`ultrax`.pre_ucenter_');define('UC_DBCONNECT','0');define('UC_KEY','123456789');define('UC_API','http://localhost/uc_server');define('UC_CHARSET','utf-8');define('UC_IP','');define('UC_APPID','2');define('UC_PPP','20');
新增加config.inc.php,内容如上
拷uc_client这个文件夹到这个目录
调用命令:http://localhost/uc_server/avatar2.php?username=shanfu.wu&size=big
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。