-
Notifications
You must be signed in to change notification settings - Fork 3
/
handler.php
46 lines (40 loc) · 1.26 KB
/
handler.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
<?php
// This could be replaced with composer autoload
include "../src/NgFileChunk.php";
include "../src/NGUCException.php";
include "../src/NgUploadChunked.php";
// by default tempDirectory will use the php tmp dir
// or the sys temp dir if not specified
$TEMP_DIR = __DIR__ . "/../temp/upload_tmp";
$UPLOAD_DIR = __DIR__ . "/../temp/upload_test";
if (empty($_REQUEST['_uniqueId'])) {
echo "Action Invalid";
return;
}
$nguc = new \NGUC\NgUploadChunked([
"uploadDirectory" => $UPLOAD_DIR,
"tempDirectory" => $TEMP_DIR,
]);
switch ($_GET['q']) {
case "upload":
try {
// Contains the information of the current chunk
$chunk = new \NGUC\NgFileChunk();
$chunk->populate($_POST['_uniqueId'], $_FILES['file']['name']);
// Process the upload
$nguc->process($chunk);
// response the path when finished
if ($nguc->isFinished()) {
echo $nguc->getUploadPath();
}
} catch (\NGUC\NGUCException $e) {
echo "ERROR: " . $e->getCode() . " - " . $e->getMessage();
}
break;
case "status":
echo $nguc->getUploadedSize($_GET['_uniqueId']);
break;
default:
echo "Action Invalid";
break;
}