PHP Image Upload Function.
$max_width || $height > $max_heigh){ if($width > $height){ $percent = $max_width / $width; $newwidth = $width * $percent; $newheight = $height * $percent; } else{ $percent = $max_heigh / $height; $newwidth = $width * $percent; $newheight = $height * $percent; } } $thumb = imagecreatetruecolor($newwidth, $newheight); if($ext=='jpg' || $ext=='jpeg') $source = imagecreatefromjpeg($_FILES['userfile']['tmp_name']); if($ext=='gif') $source = imagecreatefromgif($_FILES['userfile']['tmp_name']); if($ext=='png') $source = imagecreatefrompng($_FILES['userfile']['tmp_name']); //Resize if($sampling = true) imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); else imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); if($ext=='jpg' || $ext=='jpeg') return imagejpeg($thumb,$filepath); if($ext=='gif') return imagegif($thumb,$filepath); if($ext=='png') return imagepng($thumb,$filepath); } return $upload; } if(isset($_FILES['userfile']['name'])){ $photo = upload_img(800, 800, "user_img/"); unset($_FILES['userfile']['name']); } else{ $photo = NULL; } ?>
Upload Image
"; else if($photo == -1) print"Image must be jpg, jpeg, gif or png"; print"
"; print"
"; print"Select file:
"; print"
"; print"
"; print"
"; $photo = 0; ?>
Exit