phpcms 分析用户头像在服务器端的保存与使用
来源:互联网 发布:ubuntu ports 源 编辑:程序博客网 时间:2024/05/22 14:07
phpcms 分析用户头像在服务器端的保存与使用
距离第一篇blog快4年了,没想到一下子就过去了
很少记录事,因为感觉一直很忙
这两天要请人安装水果电脑系统,闲下来了,写两篇文章来记记事
顺便看看markdown写文章是什么感觉
对phpcms也看了一段时间了,觉得它的实现还是不错的
对它也有感情了,应该也没时间再学第二个内容管理系统了
好,开始
[域名]/index.php?m=member&c=index&a=account_manage_avatar&t=1
这网页在firefox排版有问题,在chrome没问题
这个是登录后的phpcms用户的会员中心
在账号管理-》修改头像
选择头像后,有个保存按钮
按了之后,前端我就不分析了,后端是到了
[域名]/phpsso_server/index.php?m=phpsso&c=index&a=uploadavatar
下面带有slako字串的是我的分析
/** * 上传头像处理 * 传入头像压缩包,解压到指定文件夹后删除非图片文件 */ public function uploadavatar() { //根据用户id创建文件夹 if(isset($this->data['uid']) && isset($this->data['avatardata'])) { $this->uid = intval($this->data['uid']); $this->avatardata = $this->data['avatardata']; } else { exit('0'); } $dir1 = ceil($this->uid / 10000);//slako 一万个用户使用该目录 $dir2 = ceil($this->uid % 10000 / 1000);//slako 一万个用户中的一千个用户使用该目录 //slako 我觉得这种 //创建图片存储文件夹 $avatarfile = pc_base::load_config('system', 'upload_path').'avatar/'; $dir = $avatarfile.$dir1.'/'.$dir2.'/'.$this->uid.'/'; //slako 每一个用户有一个自己的目录 if(!file_exists($dir)) { mkdir($dir, 0777, true); } //存储flashpost图片 $filename = $dir.'180x180.jpg'; $fp = fopen($filename, 'w'); fwrite($fp, $this->avatardata); fclose($fp); $avatararr = array('180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg'); $files = glob($dir."*"); foreach($files as $_files) { if(is_dir($_files)) dir_delete($_files); if(!in_array(basename($_files), $avatararr)) @unlink($_files); } if($handle = opendir($dir)) { while(false !== ($file = readdir($handle))) { if($file !== '.' && $file !== '..') { if(!in_array($file, $avatararr)) { @unlink($dir.$file); } else { $info = @getimagesize($dir.$file); if(!$info || $info[2] !=2) { @unlink($dir.$file); } } } } closedir($handle); } //slako 把头像存为几个大小 pc_base::load_sys_class('image','','0'); $image = new image(1,0); $image->thumb($filename, $dir.'30x30.jpg', 30, 30); $image->thumb($filename, $dir.'45x45.jpg', 45, 45); $image->thumb($filename, $dir.'90x90.jpg', 90, 90); //slako 标志着该用户已经有头像了 $this->db->update(array('avatar'=>1), array('uid'=>$this->uid)); exit('1'); }
当要调取使用头像时,使用方法如
public function account_manage_avatar() { $memberinfo = $this->memberinfo; //初始化phpsso $phpsso_api_url = $this->_init_phpsso(); $ps_auth_key = pc_base::load_config('system', 'phpsso_auth_key'); $auth_data = $this->client->auth_data(array('uid'=>$this->memberinfo['phpssouid'],'sys_auth_time'=>microtime(true)), '', $ps_auth_key); $upurl = base64_encode($phpsso_api_url.'/index.php?m=phpsso&c=index&a=uploadavatar&auth_data='.$auth_data); //slako 获取头像数组的函数调用 $avatar = $this->client->ps_getavatar($this->memberinfo['phpssouid']); include template('member', 'account_manage_avatar'); }
来看看ps_getavatar
在phpcms/modules/member/classes/client.class.php中
/** * 根据phpsso uid获取头像url * @param int $uid 用户id * @return array 四个尺寸用户头像数组 */ public function ps_getavatar($uid) { $dir1 = ceil($uid / 10000); $dir2 = ceil($uid % 10000 / 1000); $url = $this->ps_api_url.'/uploadfile/avatar/'.$dir1.'/'.$dir2.'/'.$uid.'/'; $avatar = array('180'=>$url.'180x180.jpg', '90'=>$url.'90x90.jpg', '45'=>$url.'45x45.jpg', '30'=>$url.'30x30.jpg'); return $avatar; }
这记写了一个小时,实在写得慢
下一篇分析一下该系统是怎么保存发表了的文章中的图片
阅读全文
1 0
- phpcms 分析用户头像在服务器端的保存与使用
- phpcms会员中心的头像是如何上传的,数据保存在数据库吗
- iOS在更改用户头像并保存至本地沙盒目录中对于UIImagePickerController、UIAlertController的使用
- 用户头像base64编码上传与保存头像问题
- phpcms 链接ucenter修改用户头像
- 保存用户头像失败解决方法
- 使用cookie在本地保存用户的信息
- liferay在自己的portlet中上传更改用户头像
- SVN 如何废弃保存在本地的服务器端资源库位置
- 自己的头像保存下
- 在 Android 的 IM 应用中使用 asmack 库实现用户头像的传输(基于VCard协议)
- 用户头像的背景为头像的模糊头像时候
- 使用HTML5的Canvas画布来剪裁用户头像
- 使用node.js实现用户头像的上传
- swift 头像上传(3)头像保存与读取
- 安卓实现调用系统图库与相机设置头像并保存在本地及服务器
- asp.net中在服务器端获取请求用户的IP
- phpcms的使用
- [时间序列分析][6]--季节差分
- 配置grunt进行css、js的检查、合并和压缩
- 一个打砖块游戏算法
- android nfc中Ndef格式的读写
- 用户、组、id、finger
- phpcms 分析用户头像在服务器端的保存与使用
- C语言基础-零散知识点总结(二)
- Longest k-Good Segment CodeForces
- 引入名称空间之前C++变量和函数的存储方案及特点
- 算法:数制转换(栈的应用)-数据结构(6)
- 站在巨人的肩膀上!
- Sass嵌套的使用
- 微信小程序:toast的使用
- js中的数组方法