mirror of
https://github.com/filegator/filegator.git
synced 2025-07-31 20:30:31 +02:00
Fix: merging chunks after upload
This commit is contained in:
@@ -99,7 +99,7 @@ class UploadController
|
||||
if ($chunks_size >= $total_size) {
|
||||
for ($i = 1; $i <= $total_chunks; ++$i) {
|
||||
$part = $this->tmpfs->readStream($prefix.$file_name.'.part'.$i);
|
||||
$this->tmpfs->write($file_name, $part['stream']);
|
||||
$this->tmpfs->write($file_name, $part['stream'], true);
|
||||
}
|
||||
|
||||
$final = $this->tmpfs->readStream($file_name);
|
||||
|
@@ -30,11 +30,17 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function write(string $filename, $data)
|
||||
public function write(string $filename, $data, $append = false)
|
||||
{
|
||||
$filename = $this->sanitizeFilename($filename);
|
||||
|
||||
file_put_contents($this->getPath().$filename, $data);
|
||||
$flags = 0;
|
||||
|
||||
if ($append) {
|
||||
$flags = FILE_APPEND;
|
||||
}
|
||||
|
||||
file_put_contents($this->getPath().$filename, $data, $flags);
|
||||
}
|
||||
|
||||
public function getFileLocation(string $filename): string
|
||||
|
@@ -16,7 +16,7 @@ interface TmpfsInterface
|
||||
|
||||
public function findAll($pattern): array;
|
||||
|
||||
public function write(string $filename, $data);
|
||||
public function write(string $filename, $data, $append);
|
||||
|
||||
public function read(string $filename): string;
|
||||
|
||||
|
@@ -137,6 +137,23 @@ class UploadTest extends TestCase
|
||||
|
||||
$this->sendRequest('POST', '/upload', $data, $files);
|
||||
$this->assertOk();
|
||||
|
||||
$this->sendRequest('POST', '/getdir', [
|
||||
'dir' => '/',
|
||||
]);
|
||||
|
||||
$this->assertResponseJsonHas([
|
||||
'data' => [
|
||||
'files' => [
|
||||
0 => [
|
||||
'type' => 'file',
|
||||
'name' => 'sample.txt',
|
||||
'path' => '/sample.txt',
|
||||
'size' => 1572864,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUploadFileBiggerThanAllowed()
|
||||
|
Reference in New Issue
Block a user