File option type file uses relative path
authorMatthias Schmidt <gravatronics@live.com>
Thu, 7 Sep 2017 16:11:23 +0000 (18:11 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 7 Sep 2017 16:12:54 +0000 (18:12 +0200)
Close #2404

wcfsetup/install/files/lib/data/package/Package.class.php
wcfsetup/install/files/lib/system/option/FileOptionType.class.php

index b0b49d56a63affa8c3a029019939bc5b5aeb2439..e488a0c505082917eaab6ba729d4b00a81216108 100644 (file)
@@ -191,6 +191,15 @@ class Package extends DatabaseObject {
                $this->data['packageVersion'] = $packageVersion;
        }
        
+       /**
+        * Returns the absolute path to the package directory with a trailing slash.
+        * 
+        * @return      string
+        */
+       public function getAbsolutePackageDir() {
+               return FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $this->packageDir));
+       }
+       
        /**
         * Loads package requirements.
         */
index 75be6b8ca7739c189289935d0e6c1b238d83ff42..ad24d4d997171a879ba7cd3705d32095225949e6 100644 (file)
@@ -65,14 +65,15 @@ class FileOptionType extends AbstractOptionType {
                }
                
                // determine location the file will be stored at
-               $package = PackageCache::getInstance()->getPackage($option->packageID);
-               $fileLocation = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir)).$option->filelocation.'.'.$file->getFileExtension();
+               $relativeFileLocation = $option->filelocation . '.' . $file->getFileExtension();
+               
+               $fileLocation = PackageCache::getInstance()->getPackage($option->packageID)->getAbsolutePackageDir() . $relativeFileLocation;
                
                // save file
                $file->moveUploadedFile($fileLocation);
                
-               // return file location as the value to store in the database
-               return $fileLocation;
+               // return relative file location as the value to store in the database
+               return $relativeFileLocation;
        }
        
        /**