本教程实现ecshop会员头像功能,ecshop评论显示会员头像功能.修改的步骤比较多,要耐心一点,一定记得先备份。 先看图:
教程开始: 第一步:ecs_users 表加入 avatar 字段后台 SQL查询里运行以下代码: ALTER TABLE `ecs_users` ADD `avatar` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' 第二步:用户中心欢迎页显示头像打开 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 onmouseout="this.className='img'" onmouseover="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>
第三步:用户信息修改页面上传头像打开 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><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 逻辑处理打开根目录下 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()
);
第五步:打开根目下 /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'";
继续在后面找到: $info = array(); 在下面一行加入: $info['avatar'] = $row['avatar'];//会员头像 by neo (责任编辑:最模板) |






英文内衣外贸商城|ecshop英
人气:448
ecshop仿聚美优品加团购网
人气:576
Puro英文综合商城网站mag
人气:169
dedecms网络公司sincer网站模
人气:490
Magento时尚餐厅主题模板
人气:268
ecshop仿美乐乐模板|ecshop免
人气:6937