From 927a12d2803e76f3cf3672660725cc48e3f2f50f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 27 Nov 2016 15:31:25 +0100 Subject: [PATCH] Improve upload file handling for file option type In `IUploadFileValidationStrategy::validate()`, you now get proper values for `UploadFile::getImageData()`, for example. --- .../lib/system/option/FileOptionType.class.php | 2 +- .../files/lib/system/upload/UploadFile.class.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/option/FileOptionType.class.php b/wcfsetup/install/files/lib/system/option/FileOptionType.class.php index 67ead5acd5..53bd846b13 100644 --- a/wcfsetup/install/files/lib/system/option/FileOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/FileOptionType.class.php @@ -71,7 +71,7 @@ class FileOptionType extends AbstractOptionType { $fileLocation = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir)).$option->filelocation.'.'.$file->getFileExtension(); // save file - move_uploaded_file($file->getLocation(), $fileLocation); + $file->moveUploadedFile($fileLocation); // return file location as the value to store in the database return $fileLocation; diff --git a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php index a760aaf297..ed72449212 100644 --- a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php +++ b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php @@ -179,4 +179,17 @@ class UploadFile { return null; } + + /** + * Moves the uploaded file to the given location and updates the internal location value to the new location + * and the internal filename value to the new filename derived from the given location. + * + * @param string $newLocation new file location + */ + public function moveUploadedFile($newLocation) { + move_uploaded_file($this->location, $newLocation); + + $this->location = $newLocation; + $this->filename = basename($this->location); + } } -- 2.20.1