Добавление изображения if isset _FILES myfile myfile _FILES myfile tmp

 1
 2
 3
 4
 5
 6
 7
 8
 9
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
85
86
87
88
89
90
91
92
93
94
95
// ==== Добавление изображения ====
if(isset($_FILES["myfile"]))
{
$myfile = $_FILES["myfile"]["tmp_name"];
$myfile_name = $_FILES["myfile"]["name"];
$myfile_size = $_FILES["myfile"]["size"];
$myfile_type = $_FILES["myfile"]["type"];
$error_flag = $_FILES["myfile"]["error"];
$size=$myfile_size/1000;
$size_1 = round($size,2);
if($size_1<1024)
{$size_1=$size_1.' Кб';}
if($size_1>1024)
{$size_1=$size_1/1000;
$size_1 = round($size_1,2);
$size_1=$size_1.' Мб';}
if($myfile_type=="image/jpeg") $format=".jpg";
if($myfile_type=="image/gif") $format=".gif";
if($myfile_type=="image/png") $format=".png";
$newname=rand(1, 999).'-'.date('d-m-Y-H-i');
$myfile_serverroot="gallery/images/big/".$newname.$format;
$myfile_serverroot_tmp="gallery/images/big/temp/".$newname.$format;
if(($myfile_type=="image/jpeg") or ($myfile_type=="image/gif") or ($myfile_type=="image/png"))
{
if(copy($myfile, $myfile_serverroot_tmp))
{
$big_image=imagecreatefromjpeg($myfile_serverroot_tmp);
$big_width=imagesx($big_image);
$big_height=imagesy($big_image);
if(($big_width<800)||($big_width==800))
{$small_width=$big_width;
$small_height=$big_height;}
else
{
$small_width=800;
$small_height=(int)($big_height*($small_width/$big_width));
}
imageresize("gallery/images/big/".$newname.".jpg","gallery/images/big/temp/".$newname.$format,$small_width,$small_height,75);
$big_width=imagesx($big_image);
$big_height=imagesy($big_image);
if(($big_width<370)||($big_width==370))
{$small_width=$big_width;
$small_height=$big_height;}
else
{
$small_width=370;
$small_height=(int)($big_height*($small_width/$big_width));
}
imageresize("gallery/images/big/scale/".$newname.".jpg","gallery/images/big/temp/".$newname.$format,$small_width,$small_height,75);
unlink("gallery/images/big/temp/".$newname.".jpg");
$old = imageCreateFromJpeg($myfile_serverroot);
$w = imageSX($old);
$h = imageSY($old);
if($h>$w)
{$new = imagecreatetruecolor($w, $w);}
if($h<$w)
{$new = imagecreatetruecolor($h, $h);}
imageCopy($new,$old,0,0,0,0,$h,$w);
imageJpeg($new, "gallery/images/small/temp/".$newname.".jpg");
imageDestroy($old);
imageDestroy($new);
imageresize("gallery/images/small/".$newname.".jpg","gallery/images/small/temp/".$newname.$format,70,70,75);
unlink("gallery/images/small/temp/".$newname.".jpg");
if(mysql_query("INSERT INTO ".$db['tabper']."gallery (title, cat, autor, date, text, size, res, reiting, golos, img) VALUES ('".$_POST['name_img']."', '".$_SESSION['category']."', '".$_POST['autor_img']."', '".date('d.m.Y H:i')."', '".$_POST['text_img']."', '".$size_1."', '0', '0', '0', '".$newname.".jpg')", $db['db']))
print('<table width="600" height="35" border="0" align="center" cellpadding="0" cellspacing="1" class="success"><tr><td align="center"><strong>Информация успешно занесена в Базу Данных</strong></td></tr></table><div>&nbsp;</div>');
}
$_SESSION['category']="";
}
}
// ==== Конец добавления изображения ====