diff --git a/CHANGELOG.md b/CHANGELOG.md index 75cce0167..2b8f3a9fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 1. [](#improved) * Improved `$page->forms()` call, added `$page->addForms()` +1. [](#bugfix) + * Fixed a bug in `FormFlashFile::moveTo()` not deleting the old file # v1.6.0-beta.8 ## 01/25/2019 diff --git a/system/src/Grav/Framework/Form/FormFlashFile.php b/system/src/Grav/Framework/Form/FormFlashFile.php index 1f0ae59d8..f9d060eb3 100644 --- a/system/src/Grav/Framework/Form/FormFlashFile.php +++ b/system/src/Grav/Framework/Form/FormFlashFile.php @@ -61,7 +61,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath)); } - $this->flash->removeFile($this->field, $this->upload['tmp_name']); + $this->flash->removeFile($this->getClientFilename(), $this->field); } public function getSize() @@ -100,7 +100,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable public function getDestination() { - return $this->upload['path']; + return $this->upload['path'] ?? ''; } public function jsonSerialize() @@ -108,9 +108,15 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable return $this->upload; } - public function getTmpFile() : string + public function getTmpFile() : ?string { - return $this->flash->getTmpDir() . '/' . $this->upload['tmp_name']; + $tmpName = $this->upload['tmp_name'] ?? null; + + if (!$tmpName) { + return null; + } + + return $this->flash->getTmpDir() . '/' . $tmpName; } public function __debugInfo() @@ -134,6 +140,10 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable if ($this->moved) { throw new \RuntimeException('Cannot retrieve stream after it has already been moved'); } + + if (!$this->getTmpFile()) { + throw new \RuntimeException('Cannot retrieve stream as the file was not uploaded'); + } } /**