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

Rofl, I replaced $avater with $time. Thanks. Working now. I'm getting there, but now I need to fix edit account. :P

Edit - w00t it's working. Thanks a lot Feartec a nice and complex script ;)
Edited by JakkyD, Sep 1 2008, 05:56 PM.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Know I got errors if I register / edit account without changing the avatar:

Registering:

Warning: Division by zero in /home/content/j/a/k/jakkyd/html/test/include/session.php on line 327

Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/a/k/jakkyd/html/test/include/session.php:327) in /home/content/j/a/k/jakkyd/html/test/process.php on line 105

Session.php =

Line 326: list($width_orig, $height_orig) = getimagesize($avatar_tmpname);
Line 327: $ratio_orig = $width_orig/$height_orig;
Line 328: if ($width/$height > $ratio_orig) {

Process.php = header("Location: ".$session->referrer);

Editing account comes up with the same; but on different lines.
Edited by JakkyD, Sep 1 2008, 06:09 PM.
Offline Profile Quote Post Goto Top
 
feartec

ow thats not good ? i will look at the code. wait for a few minutes ok ;).
Offline Profile Quote Post Goto Top
 
feartec

It's alot of code , but i think it will work ;)
i will make soon a update with less code :P

This is for the register function:
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;

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 */
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("/home/www/iithink.freehostia.com/login/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("/home/www/iithink.freehostia.com/login/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("/home/www/iithink.freehostia.com/login/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");
}
}
}
}


this is for the edit account 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;

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 */
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 */

/* 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 */
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 */

/* 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 */
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 */

/* 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 */
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 */

/* 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");
}
}
}
}
Edited by feartec, Sep 1 2008, 06:38 PM.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Good news: You can register and edit account without any errors.
Bad news: It doesnt process anything - it doesnt register you. It says "You can now login", but there is no username in the database. :P
Offline Profile Quote Post Goto Top
 
feartec

sorry what you mean with the bad news ?
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Well I click register, it says "You can now login". So I go to login but says "Username not found" therefore nothing is being added to the database. Weird :P
Offline Profile Quote Post Goto Top
 
feartec

ow ok, i'll check it tomorrow ;)
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Got this working my fault. Simple mistake what I'm sure a lot of people do. I had the wrong path for edit account. Works perfect now. Thanks a lot Feartec!
Offline Profile Quote Post Goto Top
 
php-coder
Member Avatar

Hey guys, Sorry my first post is about something not working but i have spent several hours now trying to figure out why this isnt working, im getting no errors or anything alike, it just simply doesny upload the image to the /dir/ and add it to the users profile, any help would be appretiated as im not stuck on this one,

With Regards PHP-Coder
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