|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
Avatar System Features: - Add Avatar at register page - Edit Avatar at edit account page - Avatar can be see at profile page - If Avatar is not added at register page, give default avatar: NoAvatar.png - If Avatar is not edited at edit account page change nothing - Avatar must be png, gif or jpeg - Avatar must be 100kb - Avatar wil be resized to 100x100
All these features can be changed (if you know how) _______________________________________________
AVATAR SYSTEM:
MAKE BACKUP FOR SURE
SQL CODE
- Code:
-
ALTER TABLE `users` ADD `avatar` VARCHAR(20) NOT NULL DEFAULT 'noavatar.png'
Register.php
Add this to your form:
- Code:
-
<td>Avatar:<input type="file" name="avatar"><? echo $form->error("avatar"); ?></td>
And change the form tag to this:
- Code:
-
<form action="process.php" method="POST" enctype="multipart/form-data">
Useredit.php
Add this to your form:
- Code:
-
<td>Edit Avatar:<input type="file" name="avatar"><? echo $form->error("avatar"); ?></td>
And change the form tag to this:
- Code:
-
<form action="process.php" method="POST" enctype="multipart/form-data">
Process.php
find the procRegister function:
And change the $retval to this:
- Code:
-
$retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_FILES['avatar']['name'], $_FILES['avatar']['size'], $_FILES['avatar']['type'], $_FILES['avatar']['tmp_name'], $_POST['security_code']);
Session.php
find the register function
And Change the function register tag this:
- Code:
-
function register($subuser, $subpass, $subemail, $avatar_name, $avatar_size, $avatar_type, $avatar_tmpname, $subsecurity_code){
Add this below the email checking:
- Code:
-
/* Avatar checking */ $field = "avatar"; //Use field name for avatar $uploaded_dir = "/home/www/iithink.freehostia.com/login/include/avatar/$subuser/"; $avatar_path = $uploaded_dir . $avatar_name; $width = 100; $height = 100; $thumbsize = 100;
/* Resize Image */ list($width_orig, $height_orig) = getimagesize($avatar_tmpname); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } /* Done Resize Image */
if(empty($avatar_name)){ $avatar_name = ereg_replace('$avatar_name','noavatar.png','$avatar_name'); return $avatar_name; mkdir("/home/www/iithink.freehostia.com/login/include/avatar/$subuser", 0777); } else { if(!$avatar_tmpname){ $form->setError($field, "* Avatar does not exist"); } else { $num_char=strlen($avatar_name); if($num_char > 20){ $form->setError($field, "* Your Avatar name has $num_char characters, the limit is 20"); } else { if($avatar_size > 102400) { $form->setError($field, "* Your avatar is $avatar_size, the maximum upload size is 100kb"); } else if($avatar_type == "image/jpeg"){ mkdir("/home/www/iithink.freehostia.com/login/include/avatar/$subuser", 0777);
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromjpeg($avatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $avatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($avatar_tmpname, "$avatar_path"); } else if($avatar_type == "image/pjpeg"){ mkdir("/home/www/iithink.freehostia.com/login/include/avatar/$subuser", 0777);
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromjpeg($avatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $avatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($avatar_tmpname, "$avatar_path"); } else if($avatar_type == "image/png"){ mkdir("/home/www/iithink.freehostia.com/login/include/avatar/$subuser", 0777);
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefrompng($avatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($image_p, $avatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($avatar_tmpname, "$avatar_path"); } else if($avatar_type == "image/gif"){ mkdir("/home/www/iithink.freehostia.com/login/include/avatar/$subuser", 0777);
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromgif($avatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagegif($image_p, $avatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($avatar_tmpname, "$avatar_path"); } else { $form->setError($field, "* $avatar_type is wrong extension"); } } } }
Change the addusertodatabase tag to this:
- Code:
-
/* No errors, add the new account to the */ else{ if($database->addNewUser($subuser, md5($subpass), $subemail, $avatar_name)){ if(EMAIL_WELCOME){ $mailer->sendWelcome($subuser,$subemail,$subpass); } return 0; //New user added succesfully }else{ return 2; //Registration attempt failed } } }
find the editaccount function tag
And change the editaccount tag to this:
- Code:
-
function editAccount($subcurpass, $subnewpass, $subemail, $savatar_name, $savatar_size, $savatar_type, $savatar_tmpname){
Add below the email checking in editaccount function:
- Code:
-
/* Avatar checking */ $field = "avatar"; //Use field name for avatar $uploaded_dir = "/home/www/iithink.freehostia.com/login/include/avatar/$this->username/"; $avatar_path = $uploaded_dir . $savatar_name; $query = $database->getUserInfo($_SESSION['username']); $ava_name = $query['avatar']; $noavatar="noavatar.png"; $myFile = "/home/www/iithink.freehostia.com/login/include/avatar/$this->username/$ava_name"; $width = 100; $height = 100; $thumbsize = 100;
/* Resize Image */ list($width_orig, $height_orig) = getimagesize($savatar_tmpname); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } /* Done Resize Image */
if(empty($savatar_name)){ } else { if(!$savatar_tmpname){ $form->setError($field, "* Avatar does not exist"); } else { $num_char=strlen($savatar_name); if($num_char > 20){ $form->setError($field, "* Your Avatar name has $num_char characters, the limit is 20"); } else { if($savatar_size > 102400) { $form->setError($field, "* Your avatar is $savatar_size, the maximum upload size is 100kb"); } else if($savatar_type == "image/jpeg"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromjpeg($savatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $savatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($savatar_tmpname, "$avatar_path"); } else if($savatar_type == "image/pjpeg"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromjpeg($savatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $savatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($savatar_tmpname, "$avatar_path"); } else if($avatar_type == "image/png"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefrompng($savatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($image_p, $savatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($savatar_tmpname, "$avatar_path"); } else if($savatar_type == "image/gif"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* Resize Image */ $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromgif($savatar_tmpname); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig);
imagegif($image_p, $savatar_tmpname, 100); /* Done Resize Image */
move_uploaded_file($savatar_tmpname, "$avatar_path"); } else { $form->setError($field, "* $savatar_type is wrong extension"); } } } }
Add below the change email :
- Code:
-
/* Change Avatar */ if(empty($savatar_name)){ } else if($savatar_name){ $database->updateUserField($this->username,"avatar",$savatar_name); }
Database.php
find the addnewuser function
And change the addnewuser function to this:
- Code:
-
function addNewUser($username, $password, $email, $avatar){ $time = time(); /* If admin sign up, give admin user level */ if(strcasecmp($username, ADMIN_NAME) == 0){ $ulevel = ADMIN_LEVEL; }else{ $ulevel = USER_LEVEL; } $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time, '$avatar')"; return mysql_query($q, $this->connection); }
GOOD LUCK
Edited by feartec, Sep 1 2008, 02:22 PM.
|