All pastes #717980 Raw Edit

Someone

public text v1 · immutable
#717980 ·published 2007-09-28 00:29 UTC
rendered paste body
			$filename = $_FILES['uploadedfile']['name'];
			$target_path = "../images/";
			while(file_exists($target_path . basename($filename))){
				$filename = rand(1000000,9999999) . substr($filename, -4);
			}
			$target_path = $target_path . basename($filename); 
			$orig_path = $target_path;
			if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

				$uploadedfile = $target_path;
				switch(substr($uploadedfile,-3)){
					case "jpg":
						$src = imagecreatefromjpeg($uploadedfile);
					break;
					case "peg":
						$src = imagecreatefromjpeg($uploadedfile);
					break;
					case "gif":
						$src = imagecreatefromgif($uploadedfile);
					break;
				}
				list($width,$height)=getimagesize($uploadedfile);
				$newwidth=300;
				$newheight=($height/$width)*$newwidth;
				$tmp=imagecreatetruecolor($newwidth,$newheight);
				imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
				$background = imagecolorallocate($tmp, 255, 255, 255);
				$thisfilename = substr($target_path,0,-3) . "jpg";
				imagejpeg($tmp,$thisfilename,100);
				imagedestroy($src);
				imagedestroy($tmp);
				unlink($orig_path);