I'm trying to configure KCFinder to upload to the private_files directory that I created outside of the web root. However, it seems like this may not be possible without hacking some library or module files as the KCFinder upload path requires the absolute URL of the website file upload path. I'd rather set this to my private file upload path "/var/www/private_files" My best guess is that I can hardcode this in /var/www/my_site/sites/all/libraries/kcfinder/core/class/uploader.php but I don't know exactly what to change in this section, or if that will work at all:

    if (preg_match('/^([a-z]+)\:\/\/([^\/^\:]+)(\:(\d+))?\/(.+)\/?$/',
            $this->config['uploadURL'], $patt)
    ) {
        list($unused, $protocol, $domain, $unused, $port, $path) = $patt;
        $path = path::normalize($path);
        $this->config['uploadURL'] = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/$path";
        $this->config['uploadDir'] = strlen($this->config['uploadDir'])
            ? path::normalize($this->config['uploadDir'])
            : path::url2fullPath("/$path");
        $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
        $this->typeURL = "{$this->config['uploadURL']}/{$this->type}";

    // SITE ROOT
    } elseif ($this->config['uploadURL'] == "/") {
        $this->config['uploadDir'] = strlen($this->config['uploadDir'])
            ? path::normalize($this->config['uploadDir'])
            : path::normalize($_SERVER['DOCUMENT_ROOT']);
        $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
        $this->typeURL = "/{$this->type}";

    } else {
        $this->config['uploadURL'] = (substr($this->config['uploadURL'], 0, 1) === "/")
            ? path::normalize($this->config['uploadURL'])
            : path::rel2abs_url($this->config['uploadURL']);
        $this->config['uploadDir'] = strlen($this->config['uploadDir'])
            ? path::normalize($this->config['uploadDir'])
            : path::url2fullPath($this->config['uploadURL']);
        $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
        $this->typeURL = "{$this->config['uploadURL']}/{$this->type}";

1 Answer 1


I found a solution that works at least in my case. I was on the right path... If you simply want to hardcode an upload path, you just need to configure two things in the uploader.php, the uploadDir where the files will be stored, and the Drupal URL where Drupal can find the private files, in my case:


    // hardcode private file upload path outside of web root, can't be configured through the UI that I could find
    $this->config['uploadDir'] = '/var/www/private_files';
    // hardcode the private file url that Drupal needs to be able to access private files internally        
    $this->config['uploadURL'] = '/system/files';

I know uploadDir already because that's where I've already configured private files to be stored. To find uploadDir, I linked to a private file already located in /var/www/private_files, then double clicked to see the first part of the URL on the dialog that points to where the root of /var/www/private_files is located.

The next thing I had to do was disable htaccess checking in the KCEditor config file (/sites/all/libraries/kceditor/conf/config.php) by setting '_check4htaccess' => false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.