Welcome Guest [Log In] [Register]
Add Reply
Avatar System
Topic Started: Aug 14 2008, 10:58 PM (1,634 Views)
feartec

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 :P
Edited by feartec, Sep 1 2008, 02:22 PM.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Hey guys I'm back from my holiday. Looking forward to seeing this feartec =D
Offline Profile Quote Post Goto Top
 
Admin
Administrator
also back from my holidays :)

Seems like people actually starting to help. Lots of new things. I will continue to work on a variety of things.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

How was it, where did you go?
Offline Profile Quote Post Goto Top
 
feartec

hello, im back too, i will post it later this day. Im alot bussy with my new site:

http://xileon.freehostia.com/

still need to add the login system, but first the other things must to be finish.
Edited by feartec, Aug 23 2008, 11:55 PM.
Offline Profile Quote Post Goto Top
 
feartec

AVATAR SYSTEM ADDED Look to my first post READ IT very carefull
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Whats the SQL ? Or dont you need it.
Edited by JakkyD, Sep 1 2008, 12:25 PM.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Hm know matter what I do I keep getting this:

Code:
 


Warning: mkdir() [function.mkdir]: No such file or directory in /home/content/j/a/k/jakkyd/html/test/include/session.php on line 350

Warning: move_uploaded_file(/test/images/avatar/testerlol/RealPlayer.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/j/a/k/jakkyd/html/test/include/session.php on line 360

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpODLxj6' to '/test/images/avatar/testerlol/RealPlayer.jpg' in /home/content/j/a/k/jakkyd/html/test/include/session.php on line 360

Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/a/k/jakkyd/html/test/include/session.php:350) in /home/content/j/a/k/jakkyd/html/test/process.php on line 117
Offline Profile Quote Post Goto Top
 
feartec

You have to create a folder named avatar in the include folder + you must create a noavatar.png and put that in the avatar folder ;) the sql wil i post in my first post!

if you want to let it see on the userpage you have to add this :

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="path/to/include/avatar/<? echo $getavatar; ?>">
<?
} else {
?>
<img src="path/to/include/avatar/<? echo $req_user; ?>/<? echo $getavatar; ?>">
<?
}
?>
Edited by feartec, Sep 1 2008, 02:26 PM.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Right thanks. Also does it have to be in the includes? Because I changed everything and made it in the images/avater/ folder. Thanks.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Other · Next Topic »
Add Reply