Uploadscript ook voor andere extensies
Het onderstaande upload script is nu alleen bedoeld voor de extensie .jpg
Graag zou ik dat willen uitbreiden naar andere extensies zoals .gif, .bmp enzo.
Alleen krijg ik dat niet voor elkaar. Waar ligt de oplossing hiervoor?
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
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
<?
$path = "images/"; // folder waarin de plaatjes moet komen
$max_witdh = 640; // de maximale hoogte van het plaatje
$max_height = 480; // de maximale breedte van het plaatje
$name = "pict"; // naam van het plaatje (eerst bestand wordt pict0.jpg, pict1.jpg, etc...)
$kwaliteit = "65"; // kwaliteit waarmee de JPG bewaard wordt
set_time_limit("0");
function ImageCopyResampleBicubic (&$dst_img, &$src_img, $dst_x,
$dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
$palsize = ImageColorsTotal ($src_img);
for ($i = 0; $i < $palsize; $i++) { // get palette.
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'],
$colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = (int) ($scaleX / 2);
$scaleY2 = (int) ($scaleY / 2);
for ($j = $src_y; $j < $dst_h; $j++) {
$sY = (int) ($j * $scaleY);
$y13 = $sY + $scaleY2;
for ($i = $src_x; $i < $dst_w; $i++) {
$sX = (int) ($i * $scaleX);
$x34 = $sX + $scaleX2;
$color1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX,
$y13));
$color2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX,
$sY));
$color3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34,
$y13));
$color4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34,
$sY));
$red = ($color1['red'] + $color2['red'] + $color3['red'] +
$color4['red']) / 4;
$green = ($color1['green'] + $color2['green'] + $color3['green'] +
$color4['green']) / 4;
$blue = ($color1['blue'] + $color2['blue'] + $color3['blue'] +
$color4['blue']) / 4;
ImageSetPixel ($dst_img, $i + $dst_x - $src_x, $j + $dst_y - $src_y,
ImageColorClosest ($dst_img, $red, $green, $blue));
}
}
}
$file = $_FILES["image"]["name"]; // pakt bestandsnaam van de geselecteerde plaatje
$image = $_FILES["image"]["tmp_name"];
$type = $_FILES["image"]["type"]; // bestands type pakken
if ($type == "image/pjpeg" XOR $type == "image/jpeg") {
$src_img = ImageCreateFromJPEG($image);
$img_w = imagesx($src_img);
$img_h = imagesy($src_img);
if ($img_w > $img_h) {
if ($img_w > $max_witdh) {
$dst_w = $max_witdh;
$factor = $img_w / $dst_w;
$dst_h = $img_h / $factor;
} else {
$dst_w = $img_w;
$dst_h = $img_h;
}
} else {
if ($img_h > $max_height) {
$dst_h = $max_height;
$factor = $img_h / $dst_h;
$dst_w = $img_w / $factor;
} else {
$dst_w = $img_w;
$dst_h = $img_h;
}
}
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
$end=strpos($phpinfo," ");
$phpinfo=substr($phpinfo,0,$end);
$phpinfo=substr($phpinfo,7);
if(version_compare("2.0", "$phpinfo")==1) {
$dst_img = imagecreate($dst_w,$dst_h);
} else {
$dst_img = imagecreatetruecolor($dst_w,$dst_h);
}
if($img_w > $max_witdh || $img_h > $max_height) {
ImageCopyResampleBicubic($dst_img,$src_img,0,0,0,0,$dst_w,$dst_h,$img_w,$img_h);
} else {
imagecopy($dst_img,$src_img,0,0,0,0,$img_w,$img_h);
}
if (!file_exists($path)) {
mkdir($path, 0775);
}
$i = 0;
while (file_exists($path.$name.$i.".jpg")) {
$i = $i + 1;
}
$name = $name . $i;
imagejpeg($dst_img, $path.$name.".jpg", $kwaliteit);
imagedestroy($dst_img);
imagedestroy($src_img);
Echo "<img src=\"".$path.$name.".jpg\" borer=\"0\"><p>";
Echo "Je plaatje is correct toegevoegd.";
} else {
echo "Alleen JPG files!!! (of een ander bericht)";
}
?>
$path = "images/"; // folder waarin de plaatjes moet komen
$max_witdh = 640; // de maximale hoogte van het plaatje
$max_height = 480; // de maximale breedte van het plaatje
$name = "pict"; // naam van het plaatje (eerst bestand wordt pict0.jpg, pict1.jpg, etc...)
$kwaliteit = "65"; // kwaliteit waarmee de JPG bewaard wordt
set_time_limit("0");
function ImageCopyResampleBicubic (&$dst_img, &$src_img, $dst_x,
$dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
$palsize = ImageColorsTotal ($src_img);
for ($i = 0; $i < $palsize; $i++) { // get palette.
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'],
$colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = (int) ($scaleX / 2);
$scaleY2 = (int) ($scaleY / 2);
for ($j = $src_y; $j < $dst_h; $j++) {
$sY = (int) ($j * $scaleY);
$y13 = $sY + $scaleY2;
for ($i = $src_x; $i < $dst_w; $i++) {
$sX = (int) ($i * $scaleX);
$x34 = $sX + $scaleX2;
$color1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX,
$y13));
$color2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX,
$sY));
$color3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34,
$y13));
$color4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34,
$sY));
$red = ($color1['red'] + $color2['red'] + $color3['red'] +
$color4['red']) / 4;
$green = ($color1['green'] + $color2['green'] + $color3['green'] +
$color4['green']) / 4;
$blue = ($color1['blue'] + $color2['blue'] + $color3['blue'] +
$color4['blue']) / 4;
ImageSetPixel ($dst_img, $i + $dst_x - $src_x, $j + $dst_y - $src_y,
ImageColorClosest ($dst_img, $red, $green, $blue));
}
}
}
$file = $_FILES["image"]["name"]; // pakt bestandsnaam van de geselecteerde plaatje
$image = $_FILES["image"]["tmp_name"];
$type = $_FILES["image"]["type"]; // bestands type pakken
if ($type == "image/pjpeg" XOR $type == "image/jpeg") {
$src_img = ImageCreateFromJPEG($image);
$img_w = imagesx($src_img);
$img_h = imagesy($src_img);
if ($img_w > $img_h) {
if ($img_w > $max_witdh) {
$dst_w = $max_witdh;
$factor = $img_w / $dst_w;
$dst_h = $img_h / $factor;
} else {
$dst_w = $img_w;
$dst_h = $img_h;
}
} else {
if ($img_h > $max_height) {
$dst_h = $max_height;
$factor = $img_h / $dst_h;
$dst_w = $img_w / $factor;
} else {
$dst_w = $img_w;
$dst_h = $img_h;
}
}
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
$end=strpos($phpinfo," ");
$phpinfo=substr($phpinfo,0,$end);
$phpinfo=substr($phpinfo,7);
if(version_compare("2.0", "$phpinfo")==1) {
$dst_img = imagecreate($dst_w,$dst_h);
} else {
$dst_img = imagecreatetruecolor($dst_w,$dst_h);
}
if($img_w > $max_witdh || $img_h > $max_height) {
ImageCopyResampleBicubic($dst_img,$src_img,0,0,0,0,$dst_w,$dst_h,$img_w,$img_h);
} else {
imagecopy($dst_img,$src_img,0,0,0,0,$img_w,$img_h);
}
if (!file_exists($path)) {
mkdir($path, 0775);
}
$i = 0;
while (file_exists($path.$name.$i.".jpg")) {
$i = $i + 1;
}
$name = $name . $i;
imagejpeg($dst_img, $path.$name.".jpg", $kwaliteit);
imagedestroy($dst_img);
imagedestroy($src_img);
Echo "<img src=\"".$path.$name.".jpg\" borer=\"0\"><p>";
Echo "Je plaatje is correct toegevoegd.";
} else {
echo "Alleen JPG files!!! (of een ander bericht)";
}
?>
<html>
<form action="resize.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" size="80">
<input type="submit" name="Submit" value="Submit">
</form>
</html>
Er zijn nog geen reacties op dit bericht.