Improve upload file handling for file option type
authorMatthias Schmidt <gravatronics@live.com>
Sun, 27 Nov 2016 14:31:25 +0000 (15:31 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 27 Nov 2016 14:31:25 +0000 (15:31 +0100)
In `IUploadFileValidationStrategy::validate()`, you now get proper
values for `UploadFile::getImageData()`, for example.

wcfsetup/install/files/lib/system/option/FileOptionType.class.php
wcfsetup/install/files/lib/system/upload/UploadFile.class.php

index 67ead5acd5a2d7fd069ce087cb1082c3eb5b240a..53bd846b135dbff3fa96f894ad152d83d1d88c2a 100644 (file)
@@ -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;
index a760aaf297e6cbf4cb7e12eae297d338a4dafaee..ed724492129840bb37a04f3fac90cf4d454aa0e1 100644 (file)
@@ -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);
+       }
 }