|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
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
|