This bugtracker is archived (announcement). New tickets are created on github.com. See all framework issues, cms issues, and search the module listings for more specific bugtrackers.

Ticket #5547: 2.4.0-FileUpload.diff

File 2.4.0-FileUpload.diff, 2.0 KB (added by charden, 4 years ago)

Slightly different patch to solve the same problem, updated to use Filesystem::$file_create_mask to set file permissions.

  • mysite/code/Page.php

    diff -Nur 1/mysite/code/Page.php 2/mysite/code/Page.php
    1 2  
    3838                Requirements::themedCSS('typography');  
    3939                Requirements::themedCSS('form');  
    4040        } 
    41 } 
    42  No newline at end of file 
     41} 
  • sapphire/filesystem/Folder.php

    diff -Nur 1/sapphire/filesystem/Folder.php 2/sapphire/filesystem/Folder.php
    1 2  
    230230                        if($oldFile == $file && $i > 2) user_error("Couldn't fix $file$ext with $i", E_USER_ERROR); 
    231231                } 
    232232                 
    233                 if (move_uploaded_file($tmpFile['tmp_name'], "$base/$file$ext")) { 
     233                $success = false; 
     234                if(!ini_get("open_basedir")) $success = move_uploaded_file($tmpFile['tmp_name'], "$base/$file$ext"); 
     235                else $success = rename($tmpFile['tmp_name'], "$base/$file$ext"); 
     236                 
     237                if ($success) { 
    234238                        // Update with the new image 
     239                        chmod("$base/$file$ext", Filesystem::$file_create_mask); 
    235240                        return $this->constructChild(basename($file . $ext)); 
    236241                } else { 
    237242                        if(!file_exists($tmpFile['tmp_name'])) user_error("Folder::addUploadToFolder: '$tmpFile[tmp_name]' doesn't exist", E_USER_ERROR); 
  • sapphire/filesystem/Upload.php

    diff -Nur 1/sapphire/filesystem/Upload.php 2/sapphire/filesystem/Upload.php
    1 2  
    461461                // we don't validate for empty upload fields yet 
    462462                if(!isset($this->tmpFile['name']) || empty($this->tmpFile['name'])) return true; 
    463463 
    464                 if(isset($this->tmpFile['tmp_name']) && !is_uploaded_file($this->tmpFile['tmp_name']) && !SapphireTest::is_running_test()) { 
     464                if(isset($this->tmpFile['tmp_name']) && !ini_get("open_basedir") && !is_uploaded_file($this->tmpFile['tmp_name']) && !SapphireTest::is_running_test()) { 
    465465                        $this->errors[] = _t('File.NOVALIDUPLOAD', 'File is not a valid upload'); 
    466466                        return false; 
    467467                } 
     
    500500                return true; 
    501501        } 
    502502 
    503 } 
    504  No newline at end of file 
     503}