foto upload script.
Code (php)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* @author Leon Kuipers
* @copyright 2012
*/
include "connect.php";
if(isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$size_orgineel = $_FILES['myfile']['size'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$extentions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG', 'GIF', 'PNG');
if ($name)
{
if(@!getimagesize($_FILES['myfile']['tmp_name']))
{
echo 'Deze foto heeft geen breedte of hoogte.';
}
else
{
if(!in_array(strtolower(strrchr($_FILES['myfile']['name'], '.')), $extentions))
{
echo 'Deze foto extentie is niet toegestaan';
}
else
{
//info over de afbeelding
$location_orgineel = 'afbeelding_orgineel/'.$name;
move_uploaded_file($tmp_name,$location_orgineel);
$imagearray = getimagesize($location_orgineel);
$width_orgineel = $imagearray[0];
$height_orgineel = $imagearray[1];
$image_extention = pathinfo($name, PATHINFO_EXTENSION);
$format_midium = 500;
$format_small = 125;
// afbeelding check
if ($width_orgineel == $height_orgineel)
{
$case = 1;
}
if ($width_orgineel > $height_orgineel)
{
$case = 2;
}
if ($width_orgineel < $height_orgineel)
{
$case = 3;
}
switch ($case)
{
// breete en lenge evenlang
case 1:
//meidium
$height_midium = $format_midium;
$width_midium = $format_midium;
//small
$height_small = $format_small;
$width_small = $format_small;
break;
// breete breeder dan de lengte
case 2:
$height_midium = $format_midium;
$ratio_midium = $height_midium / $height_orgineel;
$width_midium = round($width_orgineel * $ratio_midium);
//small
$height_small = $format_small;
$ratio_small = $height_small / $height_orgineel;
$width_small = round($width_orgineel * $ratio_small);
break;
// hoogte hooger dan de breete
case 3:
//midium
$width_midium = $format_midium;
$ratio_midium = $width_midium / $width_orgineel;
$height_midium = round($height_orgineel * $ratio_midium);
//small
$width_small = $format_small;
$ratio_small = $width_small / $width_orgineel;
$height_small = round($height_orgineel * $ratio_small);
break;
}
switch ($image_extention)
{
case "png":
case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;
case "bmp":
case "WBMP":
$image_create = imagecreatefromwbmp($location_orgineel);
break;
case "gif":
case "GIF":
$image_create = imagecreatefromgif($location_orgineel);
break;
case "jpg":
case "JPG":
$image_create = imagecreatefromjpeg($location_orgineel);
break;
case "jpeg":
case "JPEG":
$image_create = imagecreatefromjpeg($location_orgineel);
break;
}
//midium
$Thumbnail_empty_medium = imagecreatetruecolor($width_midium, $height_midium);
imagecopyresampled($Thumbnail_empty_medium, $image_create, 0, 0, 0, 0, $width_midium, $height_midium, $width_orgineel, $height_orgineel);
$thumbnail_naam_medium = 'afbeelding_midium/'.$name;
//small
$Thumbnail_empty_small = imagecreatetruecolor($width_small, $height_small);
imagecopyresampled($Thumbnail_empty_small, $image_create, 0, 0, 0, 0, $width_small, $height_small, $width_orgineel, $height_orgineel);
$thumbnail_naam_small = 'afbeelding_small/'.$name;
switch ($image_extention)
{
case "png":
case "PNG":
//midium
imagepng($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "bmp":
case "BMP":
//midium
imagewbmp($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "gif":
case "GIF":
//midium
imagegif($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "jpg":
case "JPG":
//midium
imagejpeg($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "jpeg":
case "JPEG":
//midium
imagejpeg($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
}
}
}
}
else
{
die("Selecteer een afbeelding!");
}
}
echo 'uploaden maar';
echo "<br/><br/>
<form action='upload.php' method='POST' enctype='multipart/form-data' />
Image uploaden:
<input type='file' name='myfile' />
<input type='submit' name='submit' value='Uploaden!' />
</form>
";
?>
/**
* @author Leon Kuipers
* @copyright 2012
*/
include "connect.php";
if(isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$size_orgineel = $_FILES['myfile']['size'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$extentions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG', 'GIF', 'PNG');
if ($name)
{
if(@!getimagesize($_FILES['myfile']['tmp_name']))
{
echo 'Deze foto heeft geen breedte of hoogte.';
}
else
{
if(!in_array(strtolower(strrchr($_FILES['myfile']['name'], '.')), $extentions))
{
echo 'Deze foto extentie is niet toegestaan';
}
else
{
//info over de afbeelding
$location_orgineel = 'afbeelding_orgineel/'.$name;
move_uploaded_file($tmp_name,$location_orgineel);
$imagearray = getimagesize($location_orgineel);
$width_orgineel = $imagearray[0];
$height_orgineel = $imagearray[1];
$image_extention = pathinfo($name, PATHINFO_EXTENSION);
$format_midium = 500;
$format_small = 125;
// afbeelding check
if ($width_orgineel == $height_orgineel)
{
$case = 1;
}
if ($width_orgineel > $height_orgineel)
{
$case = 2;
}
if ($width_orgineel < $height_orgineel)
{
$case = 3;
}
switch ($case)
{
// breete en lenge evenlang
case 1:
//meidium
$height_midium = $format_midium;
$width_midium = $format_midium;
//small
$height_small = $format_small;
$width_small = $format_small;
break;
// breete breeder dan de lengte
case 2:
$height_midium = $format_midium;
$ratio_midium = $height_midium / $height_orgineel;
$width_midium = round($width_orgineel * $ratio_midium);
//small
$height_small = $format_small;
$ratio_small = $height_small / $height_orgineel;
$width_small = round($width_orgineel * $ratio_small);
break;
// hoogte hooger dan de breete
case 3:
//midium
$width_midium = $format_midium;
$ratio_midium = $width_midium / $width_orgineel;
$height_midium = round($height_orgineel * $ratio_midium);
//small
$width_small = $format_small;
$ratio_small = $width_small / $width_orgineel;
$height_small = round($height_orgineel * $ratio_small);
break;
}
switch ($image_extention)
{
case "png":
case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;
case "bmp":
case "WBMP":
$image_create = imagecreatefromwbmp($location_orgineel);
break;
case "gif":
case "GIF":
$image_create = imagecreatefromgif($location_orgineel);
break;
case "jpg":
case "JPG":
$image_create = imagecreatefromjpeg($location_orgineel);
break;
case "jpeg":
case "JPEG":
$image_create = imagecreatefromjpeg($location_orgineel);
break;
}
//midium
$Thumbnail_empty_medium = imagecreatetruecolor($width_midium, $height_midium);
imagecopyresampled($Thumbnail_empty_medium, $image_create, 0, 0, 0, 0, $width_midium, $height_midium, $width_orgineel, $height_orgineel);
$thumbnail_naam_medium = 'afbeelding_midium/'.$name;
//small
$Thumbnail_empty_small = imagecreatetruecolor($width_small, $height_small);
imagecopyresampled($Thumbnail_empty_small, $image_create, 0, 0, 0, 0, $width_small, $height_small, $width_orgineel, $height_orgineel);
$thumbnail_naam_small = 'afbeelding_small/'.$name;
switch ($image_extention)
{
case "png":
case "PNG":
//midium
imagepng($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "bmp":
case "BMP":
//midium
imagewbmp($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "gif":
case "GIF":
//midium
imagegif($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "jpg":
case "JPG":
//midium
imagejpeg($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
case "jpeg":
case "JPEG":
//midium
imagejpeg($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;
}
}
}
}
else
{
die("Selecteer een afbeelding!");
}
}
echo 'uploaden maar';
echo "<br/><br/>
<form action='upload.php' method='POST' enctype='multipart/form-data' />
Image uploaden:
<input type='file' name='myfile' />
<input type='submit' name='submit' value='Uploaden!' />
</form>
";
?>
Gewijzigd op 06/05/2012 16:28:33 door Hoi geen
- SanThe - op 06/05/2012 16:17:01:
Kleine opmerking: Als er meerdere case-waarden dezelfde handelingen moeten ondergaan kan dat simpeler.
oke dank, ik ga t veranderen
Zoals jij het nu hebt is het ook goed hoor. Echter het scheelt een hoop typwerk en het onderhoud is ook eenvoudiger.
dat is waar maar als je ipv 1000 regels maar 500 hoeft te typen, en ik ben liever lui dan moe hahahaha,