如何在Laravel中为ckeditor + kcfinder自定义上传文件夹? [英] how to customize upload folder for ckeditor+kcfinder using in Laravel?

查看:197
本文介绍了如何在Laravel中为ckeditor + kcfinder自定义上传文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用kcfinder作为Ckeditor的插件上传照片. 配置kcfinder时,请使用以下配置:

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

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

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

kcfinder has a 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"

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

感谢答案

推荐答案

只需将js文件放在公共路径中并包含在标记中即可.然后,只需一个简单的js调用即可激活编辑器:

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>

如果您正在寻找一种将浏览服务器"按钮功能与您可能已实现的数字资产管理相集成的方法,只需找到Filebrowser插件并制作一些适合您需要的模块即可.

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.

希望获得帮助!

这篇关于如何在Laravel中为ckeditor + kcfinder自定义上传文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆