upload_marks.php
1.83 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
sleep(3);
$path = '/wp-content/uploads/marks_imported/';
$targetPath = Tz\DOC_ROOT .$path;
//die($targetPath);
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$filename = $_FILES['Filedata']['name'];
$ext = substr($filename, strrpos($filename, '.') + 1);
$newfile = md5(time()).".".$ext;
//
$targetFile = str_replace('//','/',$targetPath) . $newfile;
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
}
switch ($_FILES['Filedata']['error'])
{
case 0:
//$msg = "No Error"; // comment this out if you don't want a message to appear on success.
break;
case 1:
$msg = "The file is bigger than this PHP installation allows";
break;
case 2:
$msg = "The file is bigger than this form allows";
break;
case 3:
$msg = "Only part of the file was uploaded";
break;
case 4:
$msg = "No file was uploaded";
break;
case 6:
$msg = "Missing a temporary folder";
break;
case 7:
$msg = "Failed to write file to disk";
break;
case 8:
$msg = "File upload stopped by extension";
break;
default:
$msg = "unknown error ".$_FILES['Filedata']['error'];
break;
}
If (isset($msg)) {
$return = array(
'success'=>'false'
, 'msg'=>"Error: ".$_FILES['Filedata']['error']." Error Info: ".$msg
);
die(json_encode($return));
} else {
$return = array(
'success'=>'true'
, 'filename'=>$path.$newfile
);
die(json_encode($return));
}
?>