【问题标题】:how to customize upload folder for ckeditor+kcfinder using in Laravel?如何在 Laravel 中自定义 ckeditor+kcfinder 的上传文件夹?
【发布时间】:2016-02-03 00:32:54
【问题描述】:

我正在尝试使用 kcfinder 作为 Ckeditor 的插件来上传照片。 配置 kcfinder 时,我使用此配置:

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';
};

上传已打开,我的 kcfinder config.php 有:

  '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 有一个 uploader.php

//上传文件夹初始化

    // 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']);

如何更正我的上传文件夹,例如添加帖子 ID 号。 : "/public/uploads/img/posts/$post->id"

感谢解答

【问题讨论】:

  • 你好,我需要你的帮助来理解,你是如何设置那个路线的?

标签: php laravel ckeditor laravel-4 kcfinder


【解决方案1】:

只需将 js 文件放入您的公共路径并包含在您的标记中。然后,就是一个简单的js调用来激活编辑器:

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

如果您正在寻找一种将“浏览服务器”按钮功能与您可能已经实现的数字资产管理集成的方法,只需找到 Filebrowser 插件并制作一些模块以满足您的需求。

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    相关资源
    最近更新 更多