-
Notifications
You must be signed in to change notification settings - Fork 1
/
doajaxfileupload.php
executable file
·51 lines (47 loc) · 1.61 KB
/
doajaxfileupload.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
<?php
include_once("CONSTANTS.php");
$error = "";
$msg = "";
$fileElementName = 'playlistImage';
if (!empty($_FILES[$fileElementName]['error'])) {
switch ($_FILES[$fileElementName]['error']) {
case '1':
$error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
break;
case '2':
$error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
break;
case '3':
$error = 'The uploaded file was only partially uploaded';
break;
case '4':
$error = 'No file was uploaded!';
break;
case '6':
$error = 'Missing a temporary folder';
break;
case '7':
$error = 'Failed to write file to disk';
break;
case '8':
$error = 'File upload stopped by extension';
break;
case '999':
default:
$error = 'No error code avaiable';
}
} elseif (empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none') {
$error = 'No file was uploaded!';
} else {
$target_path ='images/';
$target_path = $target_path . basename( $_FILES[$fileElementName]['name']);
move_uploaded_file($_FILES[$fileElementName]['tmp_name'], $target_path);
$msg .= "images/" . rawurlencode($_FILES[$fileElementName]['name']);
//for security reason, we force to remove all uploaded file
@unlink($_FILES[$fileElementName]);
}
echo "{";
echo "error: '" . $error . "',\n";
echo "msg: '" . $msg . "'\n";
echo "}";
?>