|
Avatar System (Fixed - Fully working and tested)
|
|
Topic Started: Dec 18 2008, 01:28 AM (1,430 Views)
|
|
php-coder
|
Dec 18 2008, 01:28 AM
Post #1
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
Ok guys as promised, the avatar system fully working and fixed, good job im kind as this was done on my dinner breaks and spare time while im working away hehe, Credits go to fear for making this system orignally, boooo's go to those who used the used the avatar system fixed the errors and never reported them for others to learn from, ok here goes.
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 A BACKUP OF ALL FILES AND DATABSE BEFORE DOING THIS AS MISTAKES ARE EASY TO MAKE!
First add this to your DB make sure it is added before timestamp or you'll come into problems later on,
- Code:
-
ALTER TABLE `users` ADD `avatar` VARCHAR(20) NOT NULL DEFAULT 'noavatar.png'
Next add this to your register.php
- 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">
Next add this to your 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:
BE SURE TO CHANGE YOUR AVATAR DIR BUT IT MUST REMAIN IN INCLUDE/AVATAR
- Code:
-
/* Avatar checking */ $field = "avatar"; //Use field name for avatar $uploaded_dir = "/var/www/html/test/include/avatar/$subuser/"; $avatar_path = $uploaded_dir . $avatar_name; $width = 100; $height = 100; $thumbsize = 100;
if(empty($avatar_name)){ $avatar_name = ereg_replace('$avatar_name','noavatar.png','$avatar_name'); return $avatar_name; mkdir("/var/www/html/test/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("/var/www/html/test/include/avatar/$subuser", 0777);
/* 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 */
/* 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("/var/www/html/test/include/avatar/$subuser", 0777);
/* 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 */
/* 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("/var/www/html/test/include/avatar/$subuser", 0777);
/* 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 */
/* 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("/var/www/html/test/include/avatar/$subuser", 0777);
/* 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 */
/* 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 = "/var/www/html/test/include/avatar/$this->username/"; $avatar_path = $uploaded_dir . $avatar_name; $query = $database->getUserInfo($_SESSION['username']); $ava_name = $query['avatar']; $noavatar="noavatar.png"; $myFile = "/var/www/html/test/include/avatar/$this->username/$avatar_name"; $width = 100; $height = 100; $thumbsize = 100;
if(empty($avatar_name)){ } 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"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* 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 */
/* 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"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* 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 */
/* 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"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* 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 */
/* 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"){ if($ava_name == $noavatar){ //Delete nothing } else { //Delete old avatar unlink($myFile); }
/* 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 */
/* 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"); } } } }
Add below the change email :
- Code:
-
/* Change Avatar */ if(empty($avatar_name)){ } else if($avatar_name){ $database->updateUserField($this->username,"avatar",$avatar_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; } $ban = '0';
$q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$avatar', $time)";
return mysql_query($q, $this->connection); }
And finally to display your avatar on different pages use this code,
**** EDITED THE FOLLOWING WITH A BETTER WAY OF USING THIS FUNCTION ****
- Code:
-
<? $query=mysql_query("SELECT avatar FROM users WHERE username='$req_user'"); $row=mysql_fetch_row($query); $avatar=$row[0]; $noavatar="noavatar.png"; if($avatar == $noavatar){ ?>
<img src="include/avatar/<? echo $noavatar; ?>"> <? } else { ?> <img src="include/avatar/<? echo $req_user; ?>/<? echo $avatar; ?>"> <? } ?>
Please read the instructions carefully as i have spent hours reading through all fears code and correcting it ( No disrespect meant to fear as he was new to php when creating this addon).
*Edit ~ Admins will be able to see and delete avatar's so that violating avatar's maybe removed at the admins descretion *
~Pc
|
|
|
| |
|
feartec
|
Dec 18 2008, 06:39 AM
Post #2
|
|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
Thanks php-coder, nice of you to correct my script
|
|
|
| |
|
php-coder
|
Dec 18 2008, 09:25 AM
Post #3
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
More than welcom mate, i forgot to alter one thing, when you register and dont upload an avatar it fails the registration with 1 error found i'll have a look a thhat later i know what the problem is.
~Pc
|
|
|
| |
|
feartec
|
Dec 18 2008, 12:45 PM
Post #4
|
|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
....
Edited by feartec, Dec 18 2008, 11:14 PM.
|
|
|
| |
|
feartec
|
Dec 18 2008, 12:47 PM
Post #5
|
|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
sorry didnt saw that
Edited by feartec, Dec 18 2008, 11:11 PM.
|
|
|
| |
|
php-coder
|
Dec 18 2008, 12:56 PM
Post #6
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
No i didnt its right at the top of the post lol
~Pc
|
|
|
| |
|
php-coder
|
Dec 18 2008, 12:57 PM
Post #7
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
ADMIN Delete this post please, thank you ~Pc
|
|
|
| |
|
php-coder
|
Dec 18 2008, 01:26 PM
Post #8
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
Keep in mind this will only display avatars for users that dont have capitals in there name which im going to post a script to stop them using capitals in there name.
~Pc
|
|
|
| |
|
claudia
|
Dec 20 2008, 06:27 PM
Post #9
|
|
- Posts:
- 17
- Group:
- Members
- Member
- #40
- Joined:
- Dec 12, 2008
|
Hello,
Thanks for the fixes PC. I followed the instructions very carefully . There were some issues though, please do not take this as criticism in any way.
1. when attempting user edit , avatar does not upload the picture to the directory nor does it display it, also did not run any error checks either.
2. When registering if avatar has not been uploaded users get a register success but when logging in user name does not exist.
What I have done is that the user now does not need to add the avatar in the registering section, but they can now edit it in the user edit section. One prob which I would like your input on is that the avatar field in the database is empty until one uploads the picture. So I need to add some code in the register function in session.php to ask it to make default noavatar.png...
Session.php
function register tag
- Code:
-
function register($subuser, $subpass, $subemail, $avatar_name, $avatar_size, $avatar_type, $avatar_tmpname){ global $database, $form, $mailer; //The database, form and mailer object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Spruce up username, check length */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5){ $form->setError($field, "* Username below 5 characters"); } else if(strlen($subuser) > 30){ $form->setError($field, "* Username above 30 characters"); } /* Check if username is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", $subuser)){ $form->setError($field, "* Username not alphanumeric"); } /* Check if username is reserved */ else if(strcasecmp($subuser, GUEST_NAME) == 0){ $form->setError($field, "* Username reserved word"); } /* Check if username is already in use */ else if($database->usernameTaken($subuser)){ $form->setError($field, "* Username already in use"); } /* Check if username is banned */ else if($database->usernameBanned($subuser)){ $form->setError($field, "* Username banned"); } }
/* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } else{ /* Spruce up password and check length*/ $subpass = stripslashes($subpass); if(strlen($subpass) < 4){ $form->setError($field, "* Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){ $form->setError($field, "* Password not alphanumeric"); } /** * Note: I trimmed the password only after I checked the length * because if you fill the password field up with spaces * it looks like a lot more characters than 4, so it looks * kind of stupid to report "password too short". */ } /* Email error checking */ $field = "email"; //Use field name for email if(!$subemail || strlen($subemail = trim($subemail)) == 0){ $form->setError($field, "* Email not entered"); } else{ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } { mkdir("include/avatar/$subuser", 0777); }
/* Errors exist, have user correct them */ if($form->num_errors > 0){ return 1; //Errors with form } /* No errors, add the new account to the */ /* 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 } } }
editaccount function tag
- Code:
-
function editAccount($subcurpass, $subnewpass, $subemail, $savatar_name, $savatar_size, $savatar_type, $savatar_tmpname){ global $database, $form; //The database and form object /* New password entered */ if($subnewpass){ /* Current Password error checking */ $field = "curpass"; //Use field name for current password if(!$subcurpass){ $form->setError($field, "* Current Password not entered"); } else{ /* Check if password too short or is not alphanumeric */ $subcurpass = stripslashes($subcurpass); if(strlen($subcurpass) < 4 || !eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){ $form->setError($field, "* Current Password incorrect"); } /* Password entered is incorrect */ if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){ $form->setError($field, "* Current Password incorrect"); } }
/* New Password error checking */ $field = "newpass"; //Use field name for new password /* Spruce up password and check length*/ $subpass = stripslashes($subnewpass); if(strlen($subnewpass) < 4){ $form->setError($field, "* New Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){ $form->setError($field, "* New Password not alphanumeric"); } } /* Change password attempted */ else if($subcurpass){ /* New Password error reporting */ $field = "newpass"; //Use field name for new password $form->setError($field, "* New Password not entered"); }
/* Email error checking */ $field = "email"; //Use field name for email if($subemail && strlen($subemail = trim($subemail)) > 0){ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } /* Avatar checking */ $field = "avatar"; //Use field name for avatar $uploaded_dir = "include/avatar/$this->username/"; $avatar_path = $uploaded_dir . $savatar_name; $query = $database->getUserInfo($_SESSION['username']); $ava_name = $query['avatar']; $noavatar="noavatar.png"; $myFile = "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)){ mkdir("include/avatar/$subuser", 0777); } 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"); } } } }
/* Errors exist, have user correct them */ if($form->num_errors > 0){ return false; //Errors with form }
/* Update password since there were no errors */ if($subcurpass && $subnewpass){ $database->updateUserField($this->username,"password",md5($subnewpass)); }
/* Change Email */ if($subemail){ $database->updateUserField($this->username,"email",$subemail); } /* Change Avatar */ if(empty($savatar_name)){ } else if($savatar_name){ $database->updateUserField($this->username,"avatar",$savatar_name); }
/* Success! */ return true; }
Database.php -> function addNewUser
- 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; } $ban = '0';
$q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$avatar', $time)";
return mysql_query($q, $this->connection); }
Process.php
procRegister function:
- Code:
-
function procRegister(){ global $session, $form; /* Convert username to all lowercase (by option) */ if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } /* Registration attempt */ $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_FILES['avatar']['name'], $_FILES['avatar']['size'], $_FILES['avatar']['type'], $_FILES['avatar']['tmp_name']); /* Registration Successful */ if($retval == 0){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } /* Registration attempt failed */ else if($retval == 2){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = false; header("Location: ".$session->referrer); } }
procEditAccount
- Code:
-
function procEditAccount(){ global $session, $form; /* Account edit attempt */ $retval = $session->editAccount($_POST['user'], $_POST['pass'], $_POST['email'], $_FILES['avatar']['name'], $_FILES['avatar']['size'], $_FILES['avatar']['type'], $_FILES['avatar']['tmp_name']);
/* Account edit successful */ if($retval){ $_SESSION['useredit'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } };
/* Initialize process */ $process = new Process;
?>
Thanks again.
Claudia
|
|
|
| |
|
php-coder
|
Dec 20 2008, 09:49 PM
Post #10
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
Hello,
Im not to sure why you had those problems but i didnt have any of them, and as for making it to show default no avatar it also does that on mine, i can give you my link to my test site via PM if you would like to test it to make sure, but other than that all i can do is give you my files and then you remove anything you dont need (My addons).
~Pc
|
|
|
| |
| 1 user reading this topic (1 Guest and 0 Anonymous)
|