upload script
ik heb een upload script van het internet geplukt.
en ik wou vragen hoe of ik hier meerder files in kan laten uploaden:
functie.php
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
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
<?php
// Image converter & uploader
function insertImage($upload, $dir, $q, $width, $height) {
/* Insert array image system
Format for array : ResizeWidth, ResizeHeight, ResizeQuality, FolderLocation
Example 1 : $image_set[] = array ('320', '240', '95', 'upload/images/resize/');
Example 1 : $image_set[] = array ('240', '180', '90', 'upload/images/thumb/');
Special format : Use 'set' for no resize. (normal upload)
Example : $image_set[] = array ('set', 'set', 'set', 'upload/images/');
NOTE : Quality settings are 1-100. FolderLocation should end with a slash '/'.
*/
// Fill this array with thumbnail settings
$image_set = array ();
@mkdir("images/".$_POST["naam"]."",0777) or die("
Er bestaan al een directory met die titel, dus tevens ook een nieuws bericht met die titel!<br>
<a href=\"javascript:history.back(-1)\">Keer terug</a>, en verzin een andere titel");
@mkdir("images/".$_POST["naam"]."/ori",0777);
@mkdir("images/".$_POST["naam"]."/thumb",0777);
$setdir = $dir;
$image_set[] = array ('set', 'set', 'set', 'images/'.$setdir.'/ori/');
$image_set[] = array (''.$width.'', ''.$height.'', ''.$q.'', 'images/'.$setdir.'/');
$image_set[] = array ('60', '30', '95', 'images/'.$setdir.'/thumb/');
// Retrieve variables of the image file
$file_type = $_FILES[$upload]['type'];
$file_temp = $_FILES[$upload]['tmp_name'];
$file_name = str_replace(array ("\\", "'", " "), array ("", "", "_"), strtolower($_FILES[$upload]['name']));
$file_ext = end(explode('.',$file_name));
// Array of ID numbers (only used if you enable MySQL option
$image_array = array();
// Check for image type (pjpeg & x-png for IE upload bug)
if (((($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) and (($file_ext == 'jpg') or ($file_ext == 'jpeg'))) or
((($file_type == 'image/png') or ($file_type == 'image/x-png')) and ($file_ext == 'png')) or
(($file_type == 'image/gif') and ($file_ext == 'gif'))) {
// Loops image thumbnail function for each row automatically
if ($image_set_list = current($image_set)) {
do {
// Load settings from array row
$resize_width = current($image_set_list);
$resize_height = next($image_set_list);
$resize_quality = next($image_set_list);
$file_path = next($image_set_list);
// Name check & rename if exists
$file_path_check = $file_path.$file_name;
$file_name_check = $file_name;
for ($i=0; (file_exists($file_path_check)); $i++) {
$file_name_check = $i."_".$file_name;
$file_path_check = $file_path.$file_name_check;
}
$file_name = $file_name_check;
$file_path = $file_path_check;
if ($resize_quality == "set") {
copy($file_temp, $file_path);
} else {
// Different function for each type
if ((($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) and (($file_ext == 'jpg') or ($file_ext == 'jpeg'))) {
$picture_org = imagecreatefromjpeg($file_temp);
} else if ((($file_type == 'image/png') or ($file_type == 'image/x-png')) and ($file_ext == 'png')) {
$picture_org = imagecreatefrompng($file_temp);
} else if (($file_type == 'image/gif') and ($file_ext == 'gif')) {
$picture_org = imagecreatefromgif($file_temp);
}
// Retrieve original image size
$picture_org_w = imagesx($picture_org);
$picture_org_h = imagesy($picture_org);
// Check aspect ratio of thumbnail and original picture
$ratio_org = $picture_org_w / $picture_org_h;
$ratio_new = $resize_width / $resize_height;
// Calculate margin space to keep aspect ratio correct
if ($ratio_new >= $ratio_org) {
$picture_margin_h = ($picture_org_h - ($picture_org_w / $ratio_new));
$picture_margin_w = 0;
} else {
$picture_margin_w = ($picture_org_w - ($picture_org_h * $ratio_new));
$picture_margin_h = 0;
}
// Create thumbnail image
$picture_new=imagecreatetruecolor($resize_width, $resize_height);
imagecopyresized($picture_new, $picture_org, 0, 0, $picture_margin_w/2, $picture_margin_h/2, $resize_width, $resize_height, $picture_org_w - $picture_margin_w, $picture_org_h - $picture_margin_h);
// Format thumbnail and move the files
if (($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) {
// JPEG generator
imagejpeg ($picture_new, $file_path, $resize_quality);
} else if (($file_type == 'image/png') or ($file_type == 'image/x-png')) {
// PNG generator
imagepng ($picture_new, $file_path, $resize_quality);
} else if ($file_type == 'image/gif') {
// GIF generator
imagegif ($picture_new, $file_path, $resize_quality);
}
// Delete temporary images
imagedestroy($picture_new);
imagedestroy($picture_org);
/* Optional : Change /* to //* to (un)enable this function
// Logs EVERY thumbnail, this is useful if you want to keep track of all files.
// This function logs the entire filepath (including filename)
mysql_query("
INSERT INTO images(
image_name
) VALUES (
'$file_path
)
") or die(mysql_error());
// Adds to list of MySQL entries. Format : ID, Name
$image_array[] = array (mysql_result(mysql_query("SELECT LAST_INSERT_ID()"), 0), $file_name);//*/
}
} while ($image_set_list = next($image_set));
}
/* Optional : Change /* to //* to (un)enable this function
// Logs only ONCE, this is useful if you don't have different loose images
// In the other folders (to prevent duplicate names - auto-renaming)
mysql_query("
INSERT INTO images(
image_name
) VALUES (
'$file_name'
)
") or die(mysql_error());
// Adds to list of MySQL entries. Format : ID, Name
$image_array[] = array (mysql_result(mysql_query("SELECT LAST_INSERT_ID()"), 0), $file_name);//*/
// Completed message
echo "\n".'<br>Uw afbeelding is toegevoegd.';
return $image_array;
} else {
// Image was not a valid type!
echo "\n".'<br>Alleen JPG, PNG en GIF bestanden zijn toegestaan.';
return false;
}
}
?>
// Image converter & uploader
function insertImage($upload, $dir, $q, $width, $height) {
/* Insert array image system
Format for array : ResizeWidth, ResizeHeight, ResizeQuality, FolderLocation
Example 1 : $image_set[] = array ('320', '240', '95', 'upload/images/resize/');
Example 1 : $image_set[] = array ('240', '180', '90', 'upload/images/thumb/');
Special format : Use 'set' for no resize. (normal upload)
Example : $image_set[] = array ('set', 'set', 'set', 'upload/images/');
NOTE : Quality settings are 1-100. FolderLocation should end with a slash '/'.
*/
// Fill this array with thumbnail settings
$image_set = array ();
@mkdir("images/".$_POST["naam"]."",0777) or die("
Er bestaan al een directory met die titel, dus tevens ook een nieuws bericht met die titel!<br>
<a href=\"javascript:history.back(-1)\">Keer terug</a>, en verzin een andere titel");
@mkdir("images/".$_POST["naam"]."/ori",0777);
@mkdir("images/".$_POST["naam"]."/thumb",0777);
$setdir = $dir;
$image_set[] = array ('set', 'set', 'set', 'images/'.$setdir.'/ori/');
$image_set[] = array (''.$width.'', ''.$height.'', ''.$q.'', 'images/'.$setdir.'/');
$image_set[] = array ('60', '30', '95', 'images/'.$setdir.'/thumb/');
// Retrieve variables of the image file
$file_type = $_FILES[$upload]['type'];
$file_temp = $_FILES[$upload]['tmp_name'];
$file_name = str_replace(array ("\\", "'", " "), array ("", "", "_"), strtolower($_FILES[$upload]['name']));
$file_ext = end(explode('.',$file_name));
// Array of ID numbers (only used if you enable MySQL option
$image_array = array();
// Check for image type (pjpeg & x-png for IE upload bug)
if (((($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) and (($file_ext == 'jpg') or ($file_ext == 'jpeg'))) or
((($file_type == 'image/png') or ($file_type == 'image/x-png')) and ($file_ext == 'png')) or
(($file_type == 'image/gif') and ($file_ext == 'gif'))) {
// Loops image thumbnail function for each row automatically
if ($image_set_list = current($image_set)) {
do {
// Load settings from array row
$resize_width = current($image_set_list);
$resize_height = next($image_set_list);
$resize_quality = next($image_set_list);
$file_path = next($image_set_list);
// Name check & rename if exists
$file_path_check = $file_path.$file_name;
$file_name_check = $file_name;
for ($i=0; (file_exists($file_path_check)); $i++) {
$file_name_check = $i."_".$file_name;
$file_path_check = $file_path.$file_name_check;
}
$file_name = $file_name_check;
$file_path = $file_path_check;
if ($resize_quality == "set") {
copy($file_temp, $file_path);
} else {
// Different function for each type
if ((($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) and (($file_ext == 'jpg') or ($file_ext == 'jpeg'))) {
$picture_org = imagecreatefromjpeg($file_temp);
} else if ((($file_type == 'image/png') or ($file_type == 'image/x-png')) and ($file_ext == 'png')) {
$picture_org = imagecreatefrompng($file_temp);
} else if (($file_type == 'image/gif') and ($file_ext == 'gif')) {
$picture_org = imagecreatefromgif($file_temp);
}
// Retrieve original image size
$picture_org_w = imagesx($picture_org);
$picture_org_h = imagesy($picture_org);
// Check aspect ratio of thumbnail and original picture
$ratio_org = $picture_org_w / $picture_org_h;
$ratio_new = $resize_width / $resize_height;
// Calculate margin space to keep aspect ratio correct
if ($ratio_new >= $ratio_org) {
$picture_margin_h = ($picture_org_h - ($picture_org_w / $ratio_new));
$picture_margin_w = 0;
} else {
$picture_margin_w = ($picture_org_w - ($picture_org_h * $ratio_new));
$picture_margin_h = 0;
}
// Create thumbnail image
$picture_new=imagecreatetruecolor($resize_width, $resize_height);
imagecopyresized($picture_new, $picture_org, 0, 0, $picture_margin_w/2, $picture_margin_h/2, $resize_width, $resize_height, $picture_org_w - $picture_margin_w, $picture_org_h - $picture_margin_h);
// Format thumbnail and move the files
if (($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) {
// JPEG generator
imagejpeg ($picture_new, $file_path, $resize_quality);
} else if (($file_type == 'image/png') or ($file_type == 'image/x-png')) {
// PNG generator
imagepng ($picture_new, $file_path, $resize_quality);
} else if ($file_type == 'image/gif') {
// GIF generator
imagegif ($picture_new, $file_path, $resize_quality);
}
// Delete temporary images
imagedestroy($picture_new);
imagedestroy($picture_org);
/* Optional : Change /* to //* to (un)enable this function
// Logs EVERY thumbnail, this is useful if you want to keep track of all files.
// This function logs the entire filepath (including filename)
mysql_query("
INSERT INTO images(
image_name
) VALUES (
'$file_path
)
") or die(mysql_error());
// Adds to list of MySQL entries. Format : ID, Name
$image_array[] = array (mysql_result(mysql_query("SELECT LAST_INSERT_ID()"), 0), $file_name);//*/
}
} while ($image_set_list = next($image_set));
}
/* Optional : Change /* to //* to (un)enable this function
// Logs only ONCE, this is useful if you don't have different loose images
// In the other folders (to prevent duplicate names - auto-renaming)
mysql_query("
INSERT INTO images(
image_name
) VALUES (
'$file_name'
)
") or die(mysql_error());
// Adds to list of MySQL entries. Format : ID, Name
$image_array[] = array (mysql_result(mysql_query("SELECT LAST_INSERT_ID()"), 0), $file_name);//*/
// Completed message
echo "\n".'<br>Uw afbeelding is toegevoegd.';
return $image_array;
} else {
// Image was not a valid type!
echo "\n".'<br>Alleen JPG, PNG en GIF bestanden zijn toegestaan.';
return false;
}
}
?>
index.php:
Code (php)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<p>Titel:
<br>
<input name="naam" type="text" id="naam">
</p>
<p>Kwaliteit:<br>
<select name="kwaliteit">
<option value="93" selected>Kies een waarde</option>
Code (php)
</select>
</p>
<p>
Breedte van het plaatje (in pixels):
<input name="width" type="text" id="width" size="4" maxlength="3">
</p>
<p>Hoogte van het plaatje (in pixels):
<input name="height" type="text" id="height" size="4" maxlength="3">
<br>
<br>
<input name="foto" type="file" id="foto">
<br>
<input name="foto" type="file" id="foto">
<br>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<p> </p>
<p>
</p>
</body>
</html>
Er zijn nog geen reacties op dit bericht.