kcfinder通过网址

时间:2015-08-04 14:16:46

标签: javascript php jquery symfony kcfinder

问题:正如kcfinder的定义中所见,我使用此链接打开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/,则上述网址的新根应为/var/www/html/web/upload/PO/200836/

尝试:我已成功为上面提供的网址(或任何网址)创建目录/var/www/html/web/upload/PO/200836/。但是,kcfinder中的根仍设置为/var/www/html/web/upload/。因此,当我打开kcfinder时,目录在内部创建,但root仍然设置为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:我也对任何其他开源 Web文件管理器PHP / jQuery解决方案持开放态度,这些解决方案可以做到这一点。使用symfony作为框架。

更新:我已尝试将默认文件夹替换为__construct() upload.php中的新修改文件夹。

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.");
    }
}

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

1 个答案:

答案 0 :(得分:0)

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

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

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