kcfinder 已通过 URL 选择了上传目录

kcfinder have upload directory selected through URL

问题: 正如在 kcfinder 的定义中所发现的,我正在使用这个 link 打开 kcfinder:

window.open('/kcfinder/browse.php?type=files&dir=files/public&subDir=/PO/200836', 'kcfinder_textbox',
            ', width=800, height=600');

在这里,我修改了 URL 以包含子目录路径,这样 URL 就变成了这样 http://192.168.212.200/kcfinder/browse.php?type=files&dir=files/public&subDir=/PO/200836

subDir 部分包含要设置的目录名称(如果不存在则创建)。在 config.php 中,我已经将一个目录设置为根目录。因此,如果提供 subDir,它将在 config.php 的根目录中创建 subDir。现在我希望这个 subDir 成为 kcfinder 的新根目录。

例如,如果我在配置中的 uploadURL/var/www/html/web/upload/,则上述 URL 的新根应该变为 /var/www/html/web/upload/PO/200836/

尝试: 我已经能够为上述 URL(或任何 URL)成功创建目录 /var/www/html/web/upload/PO/200836/。但是,kcfinder 中的 root 仍然设置为 /var/www/html/web/upload/。因此,当我打开 kcfinder 时,目录会在内部创建,但根目录仍设置为来自 config.php.

的原始根目录

我添加了以下几行来将我的根目录更改为我通过URL的子目录:

$this->config["uploadURL"] .= $_GET['subDir'];
$this->config["uploadDir"] .= $_GET['subDir'];
$this->typeDir = $this->config["uploadDir"] ."/files";
$this->typeURL = $this->config["uploadURL"] ."/files";

我也在 github 上作为 issue 提出了这个问题,但还没有得到回应。我假设我需要做的唯一更改是将根目录设置为显示到正在创建的新目录,但我不确定我应该在哪里执行此操作。

有解决办法吗?

PS:我也对任何其他 开源 网络文件管理器 PHP/jQuery 解决方案持开放态度,这些解决方案有办法做到这一点。使用 symfony 作为框架。

更新: 我试过在 upload.php__construct() 中将默认文件夹替换为新修改的文​​件夹。

public function __construct() {

    // SET CMS INTEGRATION PROPERTY
    if (isset($_GET['cms']) &&
        $this->checkFilename($_GET['cms']) &&
        is_file("integration/{$_GET['cms']}.php")
    )
        $this->cms = $_GET['cms'];

    // LINKING UPLOADED FILE
    if (count($_FILES))
        $this->file = &$_FILES[key($_FILES)];

    // CONFIG & SESSION SETUP
    $session = new session("conf/config.php");
    $this->config = $session->getConfig();
    $this->session = &$session->values;
    $this->config["uploadURL"] .= $_GET["subDir"];


    // IMAGE DRIVER INIT
    if (isset($this->config['imageDriversPriority'])) {
        $this->config['imageDriversPriority'] =
            text::clearWhitespaces($this->config['imageDriversPriority']);
        $driver = image::getDriver(explode(' ', $this->config['imageDriversPriority']));
        if ($driver !== false)
            $this->imageDriver = $driver;
    }
    if ((!isset($driver) || ($driver === false)) &&
        (image::getDriver(array($this->imageDriver)) === false)
    )
        $this->backMsg("Cannot find any of the supported PHP image extensions!");

    // WATERMARK INIT
    if (isset($this->config['watermark']) && is_string($this->config['watermark']))
        $this->config['watermark'] = array('file' => $this->config['watermark']);

    // GET TYPE DIRECTORY
    $this->types = &$this->config['types'];
    $firstType = array_keys($this->types);
    $firstType = $firstType[0];
    $this->type = (
        isset($_GET['type']) &&
        isset($this->types[$_GET['type']])
    )
        ? $_GET['type'] : $firstType;

    // LOAD TYPE DIRECTORY SPECIFIC CONFIGURATION IF EXISTS
    if (is_array($this->types[$this->type])) {
        foreach ($this->types[$this->type] as $key => $val)
            if (in_array($key, $this->typeSettings))
                $this->config[$key] = $val;
        $this->types[$this->type] = isset($this->types[$this->type]['type'])
            ? $this->types[$this->type]['type'] : "";
    }

    // COOKIES INIT
    $ip = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
    $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/';
    if (preg_match($ip, $_SERVER['HTTP_HOST']) ||
        preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST'])
    )
        $this->config['cookieDomain'] = "";
    elseif (!strlen($this->config['cookieDomain']))
        $this->config['cookieDomain'] = $_SERVER['HTTP_HOST'];
    if (!strlen($this->config['cookiePath']))
        $this->config['cookiePath'] = "/";

    // UPLOAD FOLDER INIT

    // FULL URL
    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(realpath($_SERVER['DOCUMENT_ROOT']));
        $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
        $this->typeURL = "/{$this->type}";

    // ABSOLUTE & RELATIVE
    } 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}";
    }

    // HOST APPLICATIONS INIT
    if (isset($_GET['CKEditorFuncNum'])) {
        $this->opener['name'] = "ckeditor";
        $this->opener['CKEditor'] = array('funcNum' => $_GET['CKEditorFuncNum']);

    } elseif (isset($_GET['opener'])) {
        $this->opener['name'] = $_GET['opener'];

        if ($_GET['opener'] == "tinymce") {
            if (!isset($this->config['_tinyMCEPath']) || !strlen($this->config['_tinyMCEPath']))
                $this->opener['name'] = false;

        } elseif ($_GET['opener'] == "tinymce4") {
            if (!isset($_GET['field']))
                $this->opener['name'] = false;
            else
                $this->opener['TinyMCE'] = array('field' => $_GET['field']);
        }

    } else
        $this->opener['name'] = false;

    // LOCALIZATION
    foreach ($this->langInputNames as $key)
        if (isset($_GET[$key]) &&
            preg_match('/^[a-z][a-z\._\-]*$/i', $_GET[$key]) &&
            file_exists("lang/" . strtolower($_GET[$key]) . ".php")
        ) {
            $this->lang = $_GET[$key];
            break;
        }
    $this->localize($this->lang);

    // IF BROWSER IS ENABLED
    if (!$this->config['disabled']) {

        // TRY TO CREATE UPLOAD DIRECTORY IF NOT EXISTS
        if (!$this->config['disabled'] && !is_dir($this->config['uploadDir']))
            @mkdir($this->config['uploadDir'], $this->config['dirPerms'], true);
        // CHECK & MAKE DEFAULT .htaccess
        if (isset($this->config['_check4htaccess']) &&
            $this->config['_check4htaccess']
        ) {
            $htaccess = "{$this->config['uploadDir']}/.htaccess";
            $original = $this->get_htaccess();
            if (!file_exists($htaccess)) {
                if (!@file_put_contents($htaccess, $original))
                    $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}");
            } else {
                if (false === ($data = @file_get_contents($htaccess)))
                    $this->backMsg("Cannot read .htaccess");
                if (($data != $original) && !@file_put_contents($htaccess, $original))
                    $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!");
            }
        }

        // CHECK & CREATE UPLOAD FOLDER
        if (!is_dir($this->typeDir)) {
            if (!mkdir($this->typeDir, $this->config['dirPerms']))
                $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type));
        } elseif (!is_readable($this->typeDir))
            $this->backMsg("Cannot read upload folder.");
    }
}

这会创建目录和所有内容,但不会将根文件夹设置为新创建的文件夹。该文件夹仍设置为默认根目录。

对于在这里寻找答案的任何人,我想出了一个替代解决方案,使用名为 EMElfinderBundle 的 Symfony 包,因为 KCFinder 在他们的代码中使用了 $_GET 变量,我无法更改它可能无处不在。这个包实际上比 kcfinder 更好。对于任何使用 Symfony 的人,我肯定会推荐这个。

在捆绑包中,我所做的只是在 ElFinderConfigurationReader.php

中添加以下行
$dir="";
parse_str(parse_url($this->requestStack->getCurrentRequest()->server->all()["HTTP_REFERER"])["query"]);
$driverOptions["path"] .= $dir;