-
Notifications
You must be signed in to change notification settings - Fork 43
/
Basic.php
50 lines (43 loc) · 1.31 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
<?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
*/
public static function save(string|ConfigInterface $destination, $config, ?RequestInterface $request = null): bool
{
if (! $config instanceof ConfigInterface) {
$config = new Config([
'tempDir' => $config,
]);
}
$file = new File($config, $request);
if ('GET' === $_SERVER['REQUEST_METHOD']) {
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;
}
}
return (bool) ($file->validateFile() && $file->save($destination));
}
}