-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonSAPIUploadedFile.php
More file actions
38 lines (29 loc) · 945 Bytes
/
NonSAPIUploadedFile.php
File metadata and controls
38 lines (29 loc) · 945 Bytes
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
<?php declare(strict_types=1);
/*
* This file is part of Polymorphine/Message package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Polymorphine\Message;
use RuntimeException;
class NonSAPIUploadedFile extends UploadedFile
{
protected function moveFile($source, $target): void
{
$directory = dirname($target);
if (!is_dir($directory) || !is_writeable($directory)) {
throw new RuntimeException('Cannot write into target directory');
}
$targetStream = Stream::fromResourceUri($target, 'w+b');
$this->stream->rewind();
while (!$this->stream->eof()) {
$targetStream->write($this->stream->read(4096));
}
$targetStream->close();
$this->stream->close();
if (is_file($source)) { unlink($source); }
}
}