-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrespond.php
More file actions
executable file
·58 lines (52 loc) · 1.52 KB
/
respond.php
File metadata and controls
executable file
·58 lines (52 loc) · 1.52 KB
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
<?php
function setJqueryFileAjaxResponseCode ($response, $httpResponseCode = 200) {
// setting actual response code to an error response breaks ie8
// dont -> http_response_code($httpResponseCode); if set to an error code
return $response . '' .
'#@#' . json_encode(array('status' => $httpResponseCode)) . '#@#';
}
function unzipFiles($file) {
$files = array();
foreach($file as $key => $value) {
foreach($value as $index => $val) {
if(!isset($files[$index])) {
$files[$index] = array();
}
$files[$index][$key] = $val;
}
}
return $files;
}
function uploadFile ($file) {
if(is_array($file['name'])) {
$resultsArray = array();
foreach(unzipFiles($file) as $f) {
$resultsArray[] = uploadFile($f);
}
return $resultsArray;
}
else {
if ($file["error"] > 0) {
return array('error' => $file['error']);
}
else {
move_uploaded_file(
$file["tmp_name"],
"uploads/" . $file["name"]
);
return array(
'name' => $file['name'],
'type' => $file['type'],
'size' => $file['size'],
'tmp_name' => $file['tmp_name']
);
}
}
}
$response = uploadFile($_FILES['file']);
echo setJqueryFileAjaxResponseCode(json_encode(array_merge(
array('FILES' => $response),
array('POST' => $_POST),
array('status' => 200)
)), 200);
?>