diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8f3a9fc..e6b6c21d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#improved) * Improved `$page->forms()` call, added `$page->addForms()` + * Made `FormFlashFile` more robust against deleted files (over time) 1. [](#bugfix) * Fixed a bug in `FormFlashFile::moveTo()` not deleting the old file diff --git a/system/src/Grav/Framework/Form/FormFlashFile.php b/system/src/Grav/Framework/Form/FormFlashFile.php index f9d060eb3..025d1c5ec 100644 --- a/system/src/Grav/Framework/Form/FormFlashFile.php +++ b/system/src/Grav/Framework/Form/FormFlashFile.php @@ -26,12 +26,13 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable $this->upload = $upload; $this->flash = $flash; - if ($this->isOk() && (empty($this->upload['tmp_name']) || !file_exists($this->getTmpFile()))) { + $tmpFile = $this->getTmpFile(); + if (!$tmpFile && $this->isOk()) { $this->upload['error'] = \UPLOAD_ERR_NO_FILE; } if (!isset($this->upload['size'])) { - $this->upload['size'] = $this->isOk() ? filesize($this->getTmpFile()) : 0; + $this->upload['size'] = $tmpFile && $this->isOk() ? filesize($tmpFile) : 0; } } @@ -116,7 +117,9 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable return null; } - return $this->flash->getTmpDir() . '/' . $tmpName; + $tmpFile = $this->flash->getTmpDir() . '/' . $tmpName; + + return file_exists($tmpFile) ? $tmpFile : null; } public function __debugInfo() @@ -142,7 +145,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable } if (!$this->getTmpFile()) { - throw new \RuntimeException('Cannot retrieve stream as the file was not uploaded'); + throw new \RuntimeException('Cannot retrieve stream as the file is missing'); } }