ecshop 添加会员头像功能

来源:互联网 发布:实时大数据平台spark 编辑:程序博客网 时间:2024/04/30 07:26
首先看看会员中心默认界面 

手机版界面


user.PHP 当前页面控制器中添加://头像$head_url = '../data/head/head_'.$user_id.'.jpg';$user_info['head_url'] = is_file($head_url)? $head_url.'?'.rand() : 'templates/images/preson.jpg';$smarty->assign('user_info', $user_info);html页面:user.php中添加update_head方法//更换头像elseif ($action == 'update_head') {    $user_id = $_SESSION['user_id'];    if($_FILES['head']['error'] === 0){        $head_url = '../data/head/head_'.$user_id.'.jpg';        $filename = $_FILES['head']['tmp_name'];        // Content type        header('Content-Type: image/jpeg');        // Get new sizes        list($width, $height) = getimagesize($filename);        $newwidth = 150;        $newheight = 150;        // Load        $thumb = imagecreatetruecolor($newwidth, $newheight);        $ext = pathinfo($_FILES['head']['name'],PATHINFO_EXTENSION);        if($ext == 'jpg') $ext = 'jpeg';        $func = 'imagecreatefrom'. $ext;        $source = $func($filename);        // Resize        imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);        // Output        imagejpeg($thumb,$head_url);    }    echo '1';}

不要忘记检查一下自己的/data/head是否有head目录。。。

原创粉丝点击