百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>Ecshop教程> ecshop教程:开发上传与评论显示会员头像
分享文章到:

ecshop教程:开发上传与评论显示会员头像

发布时间:12/03 来源: 浏览: 关键词:

本教程实现ecshop会员头像功能,ecshop评论显示会员头像功能.修改的步骤比较多,要耐心一点,一定记得先备份。

先看图:

Snip20150114_13.png

 

教程开始:

第一步: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
打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

相关文章

共有10人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板