if($_POST['Submit'] == "Upload") { $data = $_FILES['logo']; if($data['size'] < 2097152) // 2MB { $good = true; switch($data['type']) { case "image/pjpeg": case "image/jpeg": $ext = "jpg"; break; case "image/png": $ext = "png"; break; case "image/gif": $ext = "gif"; break; default: $good = false; $smarty->assign('messagebox_contents', "Invalid file type, please use only JPG, PNG, or GIF Images."); break; } if($good) { $filename = md5($_SESSION['UID']).".".$ext; if(@move_uploaded_file($data['tmp_name'], "images/logos/".$filename)) { switch($ext) { case "jpg": $image = imagecreatefromjpeg("images/logos/".$filename); break; case "png"; $image = imagecreatefrompng("images/logos/".$filename); break; case "gif"; $image = imagecreatefromgif("images/logos/".$filename); break; } $width = imagesx($image); $height = imagesy($image); if($width > $height) { $newwidth = 200; $newheight = $newwidth * ($height / $width); } else { $newheight = 200; $newwidth = $newheight * ($width / $height); } $newimage = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($newimage, "images/logos/".$filename, 90); $result = $db->query("UPDATE `tradesmen` SET `logo`='$filename' WHERE `id`='".$_SESSION['UID']."'"); } } } else { $smarty->assign('messagebox_contents', "The file you uploaded is too large, please make sure your image is under 2 Megabytes (MB) in size."); } }