if($_FILES["uploadfile"]["size"] > 1024*1024) {

echo "big image!";
exit;
}

$ext = substr($_FILES['uploadfile']['name'],strpos($_FILES['uploadfile']['name'],'.'),strlen($_FILES['uploadfile']['name'])-1);

$uploaddir = './avatar/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
//$file = './avatar/'.$_POST['new'].$ext;


$filetypes = array('.jpg','.gif','.bmp','.png','.JPG','.BMP','.GIF','.PNG','.jpeg','.JPEG');


if(!in_array($ext,$filetypes) && is_uploaded_file($_FILES['uploadfile']['tmp_name'])){
}else{

$fle = './avatar/'.$_POST['new'].$ext;

copy($_FILES["uploadfile"]["tmp_name"],$fle);

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {

if($ext=='.jpg' || $ext=='.jpeg') resize_jpeg($file, $fle, 99);
if($ext=='.gif') resize_gif($file, $fle, 99);

echo "success";
} else {
echo "error";
}
}

//chmod ($un_file, 0777);


$size = getimagesize($SOURCE);
if ($size === false) die ('Bad image file!');


$source = imagecreatefromjpeg($SOURCE)
or die('Cannot load original JPEG');
if ($size[0]>$size[1]){
$ratio = $size[0]/$width;
} else {
$ratio = $size[1]/$width;
}
$X = round($size[0]/$ratio);
$Y = round($size[1]/$ratio);
$target = imagecreatetruecolor($X, $Y);

imagecopyresampled(
);
imagejpeg($target, $TARGET, 100);
return $TARGET;
imagedestroy($target);
imagedestroy($source);

}

chmod ($un_file, 0777);


$size = getimagesize($SOURCE);
if ($size === false) die ('Bad image file!');

$source = imagecreatefromgif($SOURCE)
or die('Cannot load original GIF');
if ($size[0]>$size[1]){
$ratio = $size[0]/$width;
} else {
$ratio = $size[1]/$width;
}
$X = round($size[0]/$ratio);
$Y = round($size[1]/$ratio);
$target = imagecreatetruecolor($X, $Y);

imagecopyresampled(
);

imagegif($target, $TARGET, 100);
return $TARGET;
imagedestroy($target);
imagedestroy($source);

}