-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
70 lines (61 loc) · 1.63 KB
/
upload.php
File metadata and controls
70 lines (61 loc) · 1.63 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
<?php
class Actions
{
public function status()
{
$params = [
'size' => 0
];
$tmpName = $_SERVER['HTTP_X_FILE_ID'];
$tmpPath = '/tmp/test/' . $tmpName;
if (file_exists($tmpPath)) {
$size = filesize($tmpPath);
$params['size'] = $size;
}
echo json_encode($params);
}
public function upload()
{
$tmpName = $_SERVER['HTTP_X_FILE_ID'];
$tmpPath = '/tmp/test/' . $tmpName;
$fileSize = $_SERVER['HTTP_X_FILE_SIZE'];
$uploadedFileName = $_SERVER["DOCUMENT_ROOT"] . '/uploads/' . $_SERVER['HTTP_X_FILE_NAME'];
$inputHandler = fopen('php://input', "r");
if ($fileSize == filesize($tmpPath)) {
unlink($tmpPath);
}
$fileHandler = fopen($tmpPath, "a");
// save data from the input stream
while($buffer = fgets($inputHandler, 4096)) {
fwrite($fileHandler, $buffer);
}
fclose($fileHandler);
clearstatcache();
if ($fileSize == filesize($tmpPath)) {
rename($tmpPath, $uploadedFileName);
}
}
public function index()
{
include('index.html');
}
public function notFound()
{
header("HTTP/1.0 404 Not Found");
}
public function run(): void
{
$action = $_GET['action'] ?? null;
if ($action) {
if (method_exists($this, $action)) {
$this->$action();
} else {
$this->notFound();
}
} else {
$this->index();
}
}
}
$action = new Actions();
$action->run();