From: Matthias Schmidt Date: Sun, 27 Nov 2016 14:31:25 +0000 (+0100) Subject: Improve upload file handling for file option type X-Git-Tag: 3.0.0_RC_1~117^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=927a12d2803e76f3cf3672660725cc48e3f2f50f;p=GitHub%2FWoltLab%2FWCF.git Improve upload file handling for file option type In `IUploadFileValidationStrategy::validate()`, you now get proper values for `UploadFile::getImageData()`, for example. --- 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); + } }