-
Notifications
You must be signed in to change notification settings - Fork 42
/
Basic.php
54 lines (48 loc) · 1.41 KB
/
Basic.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
52
53
54
<?php
namespace Flow;
/**
* Class Basic
*
* Example for handling basic uploads
*
* @package Flow
*/
class Basic
{
/**
* @param string $destination where to save file
* @param string|ConfigInterface $config
* @param RequestInterface $request optional
* @return bool
*/
public static function save($destination, $config, RequestInterface $request = null)
{
if (!$config instanceof ConfigInterface) {
$config = new Config(array(
'tempDir' => $config,
));
}
$file = new File($config, $request);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if ($file->checkChunk()) {
header("HTTP/1.1 200 Ok");
} else {
// The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
header("HTTP/1.1 204 No Content");
return false;
}
} else {
if ($file->validateChunk()) {
$file->saveChunk();
} else {
// error, invalid chunk upload request, retry
header("HTTP/1.1 400 Bad Request");
return false;
}
}
if ($file->validateFile() && $file->save($destination)) {
return true;
}
return false;
}
}