您的位置:首页 > 运维架构

ecshop 添加会员头像功能

2017-08-17 14:58 253 查看
首先看看会员中心默认界面 



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目录。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: