mirror of
https://github.com/filegator/filegator.git
synced 2025-08-05 17:27:39 +02:00
issue with php8.1 and new full_path key found in $_FILES, fixes #295
This commit is contained in:
@@ -63,10 +63,20 @@ class UploadController
|
|||||||
$total_size = (int) $request->input('resumableTotalSize');
|
$total_size = (int) $request->input('resumableTotalSize');
|
||||||
$identifier = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('resumableIdentifier'));
|
$identifier = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('resumableIdentifier'));
|
||||||
|
|
||||||
$file = $request->files->get('file');
|
$filebag = $request->files;
|
||||||
|
$file = $filebag->get('file');
|
||||||
|
|
||||||
$overwrite_on_upload = (bool) $this->config->get('overwrite_on_upload', false);
|
$overwrite_on_upload = (bool) $this->config->get('overwrite_on_upload', false);
|
||||||
|
|
||||||
|
// php 8.1 fix
|
||||||
|
// remove new key 'full_path' so it can preserve compatibility with symfony FileBag
|
||||||
|
// see https://php.watch/versions/8.1/$_FILES-full-path
|
||||||
|
if ($file && is_array($file) && array_key_exists('full_path', $file)) {
|
||||||
|
unset($file['full_path']);
|
||||||
|
$filebag->set('file', $file);
|
||||||
|
$file = $filebag->get('file');
|
||||||
|
}
|
||||||
|
|
||||||
if (! $file || ! $file->isValid() || $file->getSize() > $this->config->get('frontend_config.upload_max_size')) {
|
if (! $file || ! $file->isValid() || $file->getSize() > $this->config->get('frontend_config.upload_max_size')) {
|
||||||
return $response->json('Bad file', 422);
|
return $response->json('Bad file', 422);
|
||||||
}
|
}
|
||||||
|
@@ -156,6 +156,31 @@ class UploadTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUploadInvalidFile()
|
||||||
|
{
|
||||||
|
$this->signIn('john@example.com', 'john123');
|
||||||
|
|
||||||
|
$file = [
|
||||||
|
'tmp_name' => TEST_FILE,
|
||||||
|
'full_path' => 'something', // new in php 8.1
|
||||||
|
'name' => 'something',
|
||||||
|
'type' => 'application/octet-stream',
|
||||||
|
'size' => 12345,
|
||||||
|
'error' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$files = ['file' => $file];
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
$this->sendRequest('GET', '/upload', $data, $files);
|
||||||
|
|
||||||
|
$this->assertStatus(204);
|
||||||
|
|
||||||
|
$this->sendRequest('POST', '/upload', $data, $files);
|
||||||
|
|
||||||
|
$this->assertStatus(422);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUploadFileBiggerThanAllowed()
|
public function testUploadFileBiggerThanAllowed()
|
||||||
{
|
{
|
||||||
$this->signIn('john@example.com', 'john123');
|
$this->signIn('john@example.com', 'john123');
|
||||||
|
Reference in New Issue
Block a user