Welcome Guest [Log In] [Register]
Add Reply
Avatar System
Topic Started: Aug 14 2008, 10:58 PM (1,633 Views)
php-coder
Member Avatar

actually ignore that post looking at the rest of the code now there is alot of small mistakes like $savatar_tmpname which should be $avatar_tmpname and ava_name which should be avatar_name, so just look through the code and correct any mistakes you see its going to be time consuming but someone is going to have to do it :)


~Pc
Offline Profile Quote Post Goto Top
 
php-coder
Member Avatar

Ok here is the Fixed code,

Obbiously you need to replace /var/www/html/test/include/avatar with the correct file paths for your avatar folder location


First Avatar Checking code that goes into session.php


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;

/* 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("/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 */
$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 */
$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 */
$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 */
$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");
}
}
}
}




Second avatar checking code that goes into session.php


Code:
 

/* Avatar checking */
$field = "avatar"; //Use field name for avatar
$uploaded_dir = "/var/wwww/html/include/avatar/$this->username/";
$avatar_path = $uploaded_dir . $avatar_name;
$query = $database->getUserInfo($_SESSION['username']);
$avatar_name = $query['avatar'];
$noavatar="noavatar.png";
$myFile = "/var/wwww/html/include/avatar/$this->username/$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)){
} 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($avatar_name == $noavatar){
//Delete nothing
} else {
//Delete old avatar
unlink($myFile);
}

/* 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($avatar_name == $noavatar){
//Delete nothing
} else {
//Delete old avatar
unlink($myFile);
}

/* 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($avatar_name == $noavatar){
//Delete nothing
} else {
//Delete old avatar
unlink($myFile);
}

/* 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($avatar_name == $noavatar){
//Delete nothing
} else {
//Delete old avatar
unlink($myFile);
}

/* 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");
}
}
}
}



This works flawlessly for me, if you are having any more problems you are doing something wrong when adding the code as it works 100% fine now.
(that wasnt aimed at anyone just a overall comment) XD

~Pc
Offline Profile Quote Post Goto Top
 
feartec

php-coder
Dec 17 2008, 08:24 PM
Obbiously you need to replace /var/www/html/test/include/avatar with the correct file paths for your avatar folder location
Didn't you know that ? i thought you knew that. May'be that was the problem, but i can't wait for busya's release.
Offline Profile Quote Post Goto Top
 
php-coder
Member Avatar

I found further problems in the avatar script which i am now fixing please bare with me as im not on my own computer.

~Pc
Offline Profile Quote Post Goto Top
 
php-coder
Member Avatar

Quote:
 

Didn't you know that ? i thought you knew that. May'be that was the problem, but i can't wait for busya's release.


Yes of course i knew that im saying that to those that may not check the code and just try and use it lol /var/www/html/test/include/avatar is my DIR not yours you were using /home/www/iithink.freehostia.com/login/include/avatar,

And the errors in the script were spelling mistake such as ava_tmpname were as it should have been avatar_tmpname, savatar were as it should have been avatar, your code it very good just a few small mistakes, as you said you were new to php when you written this :).


~Pc
Edited by php-coder, Dec 17 2008, 09:10 PM.
Offline Profile Quote Post Goto Top
 
php-coder
Member Avatar

Also to display a users avatar use this wereever you want to show it,


Code:
 

<?
$query=mysql_query("SELECT avatar FROM users WHERE username='".$session->username."'");
$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 $getavatar; ?>">
<?
}
?>


~Pc
Offline Profile Quote Post Goto Top
 
claudia

Thank you so much, I've just actually come out of hospital, so this kinds makes my day! <I'm really sad!!! I know> lol thanks again for all your hard work and efforts you guys are the best!
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Other · Next Topic »
Add Reply