how to customize upload folder for ckeditor+kcfind

2019-06-13 15:29发布

问题:

I am trying to upload photos by using kcfinder as a plugin for Ckeditor. When configuring kcfinder I use this config :

CKEDITOR.editorConfig = function(config) {
   config.filebrowserBrowseUrl = '../../../../assets/kcfinder/browse.php?type=files';
   config.filebrowserImageBrowseUrl = 'assets/kcfinder/browse.php?type=images';
   config.filebrowserFlashBrowseUrl = 'assets/kcfinder/browse.php?type=flash';
   config.filebrowserUploadUrl = '../../../../assets/kcfinder/upload.php?type=files';
   config.filebrowserImageUploadUrl = '../../../../assets/kcfinder/upload.php?type=images';
   config.filebrowserFlashUploadUrl = 'assets/kcfinder/upload.php?type=flash';
};

uploads are open and my kcfinder config.php has :

  'uploadURL' => "/uploads/img/posts/".$post->id ,
'uploadDir' => "/home/ytsejam/public_html/remake/public/uploads/img/posts/".$post->id,

    'dirPerms' => 0755,
    'filePerms' => 0644,

    'access' => array(

        'files' => array(
            'upload' => true,
            'delete' => true,
            'copy' => true,
            'move' => true,
            'rename' => true
        ),

        'dirs' => array(
            'create' => true,
            'delete' => true,
            'rename' => true
        )
    ),

kcfinder has a uploader.php

// UPLOAD FOLDER INIT

    // FULL URLid
    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}";

    // 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}";
    }
    if (!is_dir($this->config['uploadDir']))
        @mkdir($this->config['uploadDir'], $this->config['dirPerms']);

How can I correct my uploads folder adding post id number for eg. : "/public/uploads/img/posts/$post->id"

Thank for answers

回答1:

Just throw the js files in your public path and include in your markup. Then, it's just a simple js call to activate the editor:

<textarea name="content" id="content"></textarea>
<script type="text/javascript" src="<?= url('js/admin/ckeditor/ckeditor.js') ?>"></script>
<script>CKEDITOR.replace('content');</script>

If you're looking for a way to integrate the Browse Server button functionality with digital asset management you may have implemented, just find the Filebrowser plugin and make some mods to suit your needs.

Hope this help!