|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
It's alot of code , but i think it will work  i will make soon a update with less code 
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.
|