ecshop 会员头像 ################ 数据库 ################ 1、ecs_users 表加入 avatar 字段 ALTER TABLE `ecs_users` ADD `avatar` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' ################ 前端 ################ 2、themes\default\user_clips.dwt 用户中心默认显示页面 显示头像(新会员显示系统默认的头像) <!-- *用户中心默认显示页面 start--> <!-- {if $action eq 'default'} --> <style> .avtar .img a{display:none;width:72px;height:23px;background:url(images/change_avtar.gif);position:absolute;margin-left:44px;margin-top:93px} .avtar .hover a{display:block} .Left .img{border:1px solid #d0d0d0;margin-bottom:5px} .Left .img,.Left .img img{width:120px;height:120px} </style> <div class="Left avtar" style="float:left;width:122px;text-align:center;"> <div οnmοuseοut="this.className='img'" οnmοuseοver="this.className='img hover'" class="img"> <a title="修改我的头像" href="user.php?act=profile" class="red"></a> <img src="{if $info.avatar}{$info.avatar}{else}images/avatar.gif{/if}"> </div> </div> 3、themes\default\user_transaction.dwt 用户信息修改页面 <!-- 用户信息界面 start--> <!--{if $action eq 'profile'}--> 里面找到 <form name="formEdit" action="user.php" method="post" onSubmit="return userEdit()"> 修改成 <form name="formEdit" action="user.php" method="post" onSubmit="return userEdit()" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1097152" /><!-- 1M图片上传大小设置 --> 再找到submit提交之前加入 <tr> <td width="28%" align="right" bgcolor="#FFFFFF">会员头像:</td> <td width="72%" align="left" bgcolor="#FFFFFF"> <div style="width:50%;float:left;"> <input id="avatar" type="file" size="40" value="" name="avatar"> <br/> <span style="color:#FF0000"> 图片像素最佳为55px * 55px,<br/>大小不得超过1M</span> </div> <div style="width:50%;float:left;"> <img src="{if $profile.avatar}{$profile.avatar}{else}images/avatar.gif{/if}" alt="" width="55" height="55"> </div> </td> </tr> ################ php 逻辑处理 ################ 1、user.php 里面找到 require(dirname(__FILE__) . '/includes/init.php'); 它的下面加入 include_once(ROOT_PATH . '/includes/cls_image.php');//会员头像 by neo $image = new cls_image($_CFG['bgcolor']);//会员头像 by neo $allow_suffix = array('gif', 'jpg', 'png', 'jpeg', 'bmp');//会员头像 by neo 继续找到 /* 更新用户扩展字段的数据 */ 在它的上面加入 $avatar = isset($_POST['avatar']) ? $_POST['avatar'] : '';//会员头像 by neo 继续找 if (!empty($mobile_phone) && !preg_match('/^[\d-\s]+$/', $mobile_phone)) { show_message($_LANG['passport_js']['mobile_phone_invalid']); } 它下面加入 /* 检查图片:如果有错误,检查尺寸是否超过最大值;否则,检查文件类型 */ if (isset($_FILES['avatar']['error'])) // php 4.2 版本才支持 error { // 最大上传文件大小 $php_maxsize = ini_get('upload_max_filesize'); $htm_maxsize = '1M'; // 会员头像 if ($_FILES['avatar']['error'] == 0) { if (!$image->check_img_type($_FILES['avatar']['type'])) { show_message("图片格式不正确!"); } } elseif ($_FILES['avatar']['error'] == 1) { show_message(sprintf('图片文件太大了(最大值:1M),无法上传。', $php_maxsize), $_LANG['profile_lnk'], 'user.php?act=profile', 'info'); } elseif ($_FILES['avatar']['error'] == 2) { show_message(sprintf('图片文件太大了(最大值:1M),无法上传。', $htm_maxsize), $_LANG['profile_lnk'], 'user.php?act=profile', 'info'); } } /* 4.1版本 */ else { // 会员头像 if ($_FILES['avatar']['tmp_name'] != 'none') { if (!$image->check_img_type($_FILES['avatar']['type'])) { show_message("图片格式不正确!"); } } } //会员头像 by neo if (!empty($_FILES['avatar']['name'])) { /* 更新会员头像之前先删除旧的头像 */ $sql = "SELECT avatar " . " FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"; $row = $GLOBALS['db']->getRow($sql); if ($row['avatar'] != '') { @unlink($row['avatar']); } $img_name = $user_id . '.' . end(explode('.', $_FILES['avatar']['name'])); $target = ROOT_PATH . DATA_DIR . '/avatar/'; $original_img = $image->upload_image($_FILES['avatar'], 'avatar', $img_name); // 原始图片 $avatar = $image->make_thumb($original_img, 55, 55, $target); if ($avatar === false) { show_message("图片保存出错!"); } } 在它的下面还有个 $profile = array( 'user_id' => $user_id, 'email' => isset($_POST['email']) ? trim($_POST['email']) : '', 'sex' => isset($_POST['sex']) ? intval($_POST['sex']) : 0, 'birthday' => $birthday, 'other' => isset($other) ? $other : array() ); 修改成 $profile = array( 'user_id' => $user_id, 'email' => isset($_POST['email']) ? trim($_POST['email']) : '', 'sex' => isset($_POST['sex']) ? intval($_POST['sex']) : 0, 'birthday' => $birthday, 'avatar' => $avatar,//会员头像 by neo 'other' => isset($other) ? $other : array() ); 2、includes\lib_clips.php 找到 function get_user_default($user_id) { $user_bonus = get_user_bonus(); $sql = "SELECT pay_points, user_money, credit_line, last_login, is_validated FROM " .$GLOBALS['ecs']->table('users'). " WHERE user_id = '$user_id'"; 加入字段 function get_user_default($user_id) { $user_bonus = get_user_bonus(); //会员头像 by neo $sql = "SELECT pay_points, user_money, credit_line, last_login, is_validated, avatar FROM " .$GLOBALS['ecs']->table('users'). " WHERE user_id = '$user_id'"; $row = $GLOBALS['db']->getRow($sql); 继续下面中的 $info = array(); 加入字段 $info['avatar'] = $row['avatar'];//会员头像 by neo 3、includes\lib_transaction.php 找到 if (!$GLOBALS['user']->edit_user($cfg)) 在它的前面加入 //会员头像 if (!empty($profile['avatar'])) { $cfg['avatar'] = $profile['avatar']; } 继续找到 function get_profile($user_id) { global $user; /* 会员帐号信息 */ $info = array(); $infos = array(); $sql = "SELECT user_name, birthday, sex, question, answer, rank_points, pay_points,user_money, user_rank,". " msn, qq, office_phone, home_phone, mobile_phone, passwd_question, passwd_answer ". "FROM " .$GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"; 加入字段 function get_profile($user_id) { global $user; /* 会员帐号信息 */ $info = array(); $infos = array(); $sql = "SELECT user_name, birthday, sex, question, answer, rank_points, pay_points,user_money, user_rank,". " msn, qq, office_phone, home_phone, mobile_phone, passwd_question, passwd_answer, avatar ".//会员头像 by neo "FROM " .$GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"; 继续找到下面的 $info['birthday'] = isset($infos['birthday']) ? $infos['birthday'] : ''; 在它的下面加入 $info['avatar'] = isset($infos['avatar']) ? $infos['avatar'] : '';//会员头像 by neo 4、includes\modules\integrates\integrate.php 里面找到 var $error = 0; 它的下面加入 /* 会员头像 by neo */ var $field_avatar = ''; 继续找到 if ((!empty($cfg['bday'])) && $this->field_bday != 'NULL') { $values[] = $this->field_bday . "='" . $cfg['bday'] . "'"; } 在它的下面加入 //会员头像 by neo if ((!empty($cfg['avatar'])) && $this->field_avatar != 'NULL') { $values[] = $this->field_avatar . "='" . $cfg['avatar'] . "'"; } 5、includes\modules\integrates\ecshop.php 找到 $this->field_reg_date = 'reg_time'; 下面加入 $this->field_avatar = 'avatar';//会员头像 by neo ################ 后台 ################ 1、admin\templates\user_info.htm 找到 <form method="post" action="users.php" name="theForm" οnsubmit="return validate()"> 改成 <form method="post" action="users.php" name="theForm" οnsubmit="return validate()" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1097152" /><!-- 1M图片上传大小设置 --> 继续找 <tr> <td class="label">{$lang.email}:</td> <td><input type="text" name="email" maxlength="60" size="40" value="{$user.email}" />{$lang.require_field}</td> </tr> 它的下面加入 <tr> <td width="28%" align="right" class="label">会员头像:</td> <td width="72%" align="left" bgcolor="#FFFFFF"> <div style="width:50%;float:left;"> <input id="avatar" type="file" size="40" value="" name="avatar"> <br/> <span style="color:#FF0000"> 图片像素最佳为55px * 55px,<br/>大小不得超过1M</span> </div> <div style="width:50%;float:left;"> <img src="../{if $user.avatar}{$user.avatar}{else}images/avatar.gif{/if}" alt="" width="55" height="55"> </div> </td> </tr> 2、admin\users.php 找到头部的 require(dirname(__FILE__) . '/includes/init.php'); 下面加入 include_once(ROOT_PATH . '/includes/cls_image.php');//会员头像 by neo $image = new cls_image($_CFG['bgcolor']);//会员头像 by neo $allow_suffix = array('gif', 'jpg', 'png', 'jpeg', 'bmp');//会员头像 by neo 找到 $sql = "SELECT u.user_id, u.sex, u.birthday, u.pay_points, u.rank_points, u.user_rank , u.user_money, u.frozen_money, u.credit_line, u.parent_id, u2.user_name as parent_username, u.qq, u.msn, u.office_phone, u.home_phone, u.mobile_phone". 修改成 $sql = "SELECT u.user_id, u.sex, u.birthday, u.pay_points, u.rank_points, u.user_rank , u.user_money, u.frozen_money, u.credit_line, u.parent_id, u2.user_name as parent_username, u.qq, u.msn, u.office_phone, u.home_phone, u.mobile_phone, u.avatar".//会员头像 by neo 下面的 $user['mobile_phone'] = $row['mobile_phone']; 它的下面加入 $user['avatar'] = $row['avatar'];//会员头像 by neo 这样,后台编辑会员 就能看到会员的头像了。接下来,处理后台修改会员头像的提交逻辑处理 继续找到 elseif ($_REQUEST['act'] == 'update') 下面的 $credit_line = empty($_POST['credit_line']) ? 0 : floatval($_POST['credit_line']); 它的下面加入 $user_id = empty($_POST['id']) ? '' : trim($_POST['id']);//会员头像 by neo /* 检查图片:如果有错误,检查尺寸是否超过最大值;否则,检查文件类型 */ if (isset($_FILES['avatar']['error'])) // php 4.2 版本才支持 error { // 最大上传文件大小 $php_maxsize = ini_get('upload_max_filesize'); $htm_maxsize = '1M'; // 会员头像 if ($_FILES['avatar']['error'] == 0) { if (!$image->check_img_type($_FILES['avatar']['type'])) { sys_msg("图片格式不正确!", 1, array(), false); } } elseif ($_FILES['avatar']['error'] == 1) { sys_msg(sprintf('图片文件太大了(最大值:1M),无法上传。', $php_maxsize), 1, array(), false); } elseif ($_FILES['avatar']['error'] == 2) { sys_msg(sprintf('图片文件太大了(最大值:1M),无法上传。', $htm_maxsize), 1, array(), false); } } /* 4.1版本 */ else { // 会员头像 if ($_FILES['avatar']['tmp_name'] != 'none') { if (!$image->check_img_type($_FILES['avatar']['type'])) { sys_msg("图片格式不正确!"); } } } //会员头像 by neo if (!empty($_FILES['avatar']['name'])) { /* 更新会员头像之前先删除旧的头像 */ $sql = "SELECT avatar " . " FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"; $row = $GLOBALS['db']->getRow($sql); if ($row['avatar'] != '') { @unlink('../' . $row['avatar']); } $img_name = $user_id . '.' . end(explode('.', $_FILES['avatar']['name'])); $target = ROOT_PATH . DATA_DIR . '/avatar/'; $original_img = $image->upload_image($_FILES['avatar'], 'avatar', $img_name); // 原始图片 $avatar = $image->make_thumb('../' . $original_img, 55, 55, $target); if ($avatar === false) { sys_msg("图片保存出错!"); } } 下面一行的 if (!$users->edit_user(array('username'=>$username, 'password'=>$password, 'email'=>$email, 'gender'=>$sex, 'bday'=>$birthday ), 1)) 加入字段 if (!$users->edit_user(array('username'=>$username, 'password'=>$password, 'email'=>$email, 'gender'=>$sex, 'bday'=>$birthday, 'avatar'=>$avatar ), 1))//会员头像 by neo
ecshop设置会员头像
最新推荐文章于 2017-12-28 16:24:00 发布