CKEditor CKFinderを使ってS3からの呼び出しやId毎にDirectoryを分ける方法

2026/05/18

ckfinderはだと直接ディレクトリを見に行くためDBからunique_idを使い検索することができません。

なのでOSS内を直接変更する必要があります。ちなみに使用FWはCakePHPです。

今回自分がやったやり方ですが、最初にcakephpでApi用のcontrollerにシンプルにuser情報をreturnするだけのメソッドを作ります。

 public function getUserCkfinder()                                                                                 
 {   
     if ($this->getRequest()->is('ajax'))                                                                          
     {   
            return $this->response->withStringBody(json_encode($user, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS));
     }                                                                                                             
 }
         

シンプルですね、失敗した処理とか割愛です。

次に./ckfinder/getUserInformation.jsってのを作りこれも中身はシンプル

$(function () {
    const host = location.hostname;
    const protocol = location.protocol
    const url = protocol + '//' + host + '/mypage/api/getUserCkfinder';
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'json',
    })
    .done(function(data) {
        CKFinder.start({id: data.id, pass: 'user_id'});
    })
    .fail(function() {
        console.log("ajax通信に失敗しました");
    });
}); 

デフォルトでは CKFinder.start() ってのが ckfinder.htmlにあるのですが、それをAJAX通信成功後に使うようにすれば

/core/~ から降りてったconnector.phpで処理してくれるって流れです。

require_once DIR . ‘/vendor/autoload.php’;

use CKSource\CKFinder\CKFinder;

$ckfinder = new CKFinder(DIR . ‘/../../../config.php’);

$ckfinder->run();
~

サニージェム公式note

アーカイブ記事

すべて
  • 1月
  • 2月
  • 3月
  • 4月
  • 5月
  • 6月
  • 7月
  • 8月
  • 9月
  • 10月
  • 11月
  • 12月

contact us お問い合わせ

Contact お問い合わせ・ご相談

「何から相談すればいいかわからない」
そんな段階でも、お気軽にご連絡ください。

Recruit 求人へのご応募

サニージェムの考え方に共感してくれる方と、
ぜひ一緒に働きたいと思っています。