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:
|
”Framgång! ”,
1 => ”uploaded sparar överskrider upload_max_filesizedirektiv i php.ini”,
2 => ”uploaded sparar överskrider MAX_FILE_SIZE-direktiv som specificerades i HTMLEN bildar”,
3 => ”uploaded sparar endast uploaded delvist”,
ingen => 4 ”sparar uploaded”,
6 => ”saknad en tillfällig mapp”,
7 som => ”inte kan skriva, sparar till disken”,
);
//, OM DET FINNS INGENTING I $_POST SOM SÄTTS UPP BILDA FÖR, MATAR IN
om (töm ($_POST))
{
? >
Upload,
Results: File Upload\n";
// ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
// echo ""; var_dump($_FILES); var_dump($_POST); echo " \n";
// ITERATE OVER THE CONTENTS OF $_FILES
foreach ($_FILES as $my_uploaded_file)
{
// SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
$error_code = $my_uploaded_file["error"];
if ($error_code == 4) continue;
// SYNTHESIZE THE NEW FILE NAME
$f_type = trim(strtolower(end (explode( '.', basename($my_uploaded_file['name'] )))));
$f_name = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
$my_new_file = getcwd() . '/' . $uploads . '/' . $f_name .'.'. $f_type;
$my_file = $uploads . '/' . $f_name .'.'. $f_type;
// OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");
// IF THERE ARE ERRORS
if ($error_code != 0)
{
$error_message = $errors[$error_code];
die("Sorry, Upload Error Code: $error_code: $error_message");
}
// GET THE FILE SIZE
$file_size = number_format($my_uploaded_file["size"]);
// MOVE THE FILE INTO THE DIRECTORY
// IF THE FILE IS NEW
if (!file_exists($my_new_file))
{
if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
{
$upload_success = 1;
}
else
{
$upload_success = -1;
}
// IF THE FILE ALREADY EXISTS
}
else
{
echo " $my_file already exists.\n";
// SHOULD WE OVERWRITE THE FILE? IF NOT
if (empty($_POST["overwrite"]))
{
$upload_success = 0;
// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
}
else
{
$now = date('Y-m-d');
$my_bak = $my_new_file . '.' . $now . '.bak';
if (!copy($my_new_file, $my_bak))
{
echo " Attempted Backup Failed!\n";
}
if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
{
$upload_success = 2;
}
else
{
$upload_success = -1;
}
}
}
// REPORT OUR SUCCESS OR FAILURE
if ($upload_success == 2) { echo " It has been overwritten.\n"; }
if ($upload_success == 1) { echo " $my_file has been saved.\n"; }
if ($upload_success == 0) { echo " It was NOT overwritten.\n"; }
if ($upload_success < 0) { echo " ERROR $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND\n"; }
if ($upload_success > 0)
{
eka ”uploaded $file_size-byte. \ n”;
om (! chmod ($my_new_file, 0755))
{
eka ”, chmod (0755) MISSADE: fileperms () = ”;
eka substr (sprintf (”%o”, fileperms ($my_new_file)), -4);
}
eka ”, Se spara $my_file \ n ";
}
// AVSLUTAR ITERATOR
}
}
|