1 | <?php |
||
13 | class RequestHelper { |
||
14 | |||
15 | /** @var IRequest */ |
||
16 | private $request; |
||
17 | |||
18 | 2 | public function __construct(IRequest $request) { |
|
21 | |||
22 | /** |
||
23 | * Get current upload size |
||
24 | * returns null for chunks and when there is no upload |
||
25 | * |
||
26 | * @param string $path |
||
27 | * @return int|null |
||
28 | */ |
||
29 | 3 | public function getUploadSize($path) { |
|
30 | 3 | $uploadSize = null; |
|
31 | |||
32 | 3 | $requestMethod = $this->request->getMethod(); |
|
33 | 3 | $isRemoteScript = $this->isScriptName('remote.php'); |
|
34 | // Are we uploading anything? |
||
35 | 3 | if (in_array($requestMethod, ['MOVE', 'PUT']) && $isRemoteScript) { |
|
36 | // v1 && v2 Chunks are not scanned |
||
37 | if ( |
||
38 | \OC_FileChunking::isWebdavChunk() |
||
39 | || ($requestMethod === 'PUT' && strpos($path, 'uploads/') === 0) |
||
40 | ) { |
||
41 | return null; |
||
42 | } |
||
43 | |||
44 | if ($requestMethod === 'PUT') { |
||
45 | $uploadSize = (int)$this->request->getHeader('CONTENT_LENGTH'); |
||
46 | } else { |
||
47 | $uploadSize = (int)$this->request->getHeader('OC_TOTAL_LENGTH'); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | 3 | return $uploadSize; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @param string $string |
||
57 | * @return bool |
||
58 | */ |
||
59 | 3 | public function isScriptName($string) { |
|
63 | } |
||
64 |