- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
$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;