簡體   English   中英

如何使用CK Finder 3自動將圖像保存在其他文件夾中

[英]How can I automatically save images in different folder with CK Finder 3

我很難使新版本的CKFinder(CKFinder 3)像舊版本一樣工作。 該系統用於自動檢測圖像文件並將其存儲在“圖像”子文件夾中,對於所有其他文件,將其存儲在“文件”子文件夾中。

現在看來,當您導航到“瀏覽服務器”彈出窗口中的文件夾並單擊images文件夾后添加文件時,images子文件夾僅會保存文件。 上載並單擊“發送到服務器”也會將所有文件發送到“文件”子文件夾,而與文件類型無關。

這樣做的主要問題是,它會忽略為圖像設置的文件大小規則,除非導航到images文件夾,然后它將強制執行。 這也不太方便,因為用戶不太可能每次都導航到該子文件夾。

目前,我已經為CKFinder 3設置了config.php,如下所示:

$config['backends'][] = array(
    'name'         => 'default',
    'adapter'      => 'local',
    'baseUrl'      => $baseDir, // "/mywebsite/sites/default/uploads/"
    //'root'         => '', // Can be used to explicitly set the CKFinder user files directory.
    'chmodFiles'   => 0777,
    'chmodFolders' => 0755,
    'filesystemEncoding' => 'UTF-8',
);


/*================================ Resource Types =====================================*/
// https://ckeditor.com/docs/ckfinder/ckfinder3-php/configuration.html#configuration_options_resourceTypes

$config['defaultResourceTypes'] = '';

$config['resourceTypes'][] = array(
    'name'              => 'Files', // Single quotes not allowed.
    'directory'         => '/files/',
    'maxSize'           => '10M',
    'allowedExtensions' => '7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gz,gzip,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip,gif,jpeg,jpg,png,svg',
    'deniedExtensions'  => '',
    'backend'           => 'default',
);

$config['resourceTypes'][] = array(
    'name'              => 'Images',
    'directory'         => '/images/',
    'maxSize'           => '500K',
    'allowedExtensions' => 'bmp,gif,jpeg,jpg,png,svg',
    'deniedExtensions'  => '',
    'backend'           => 'default',
);

任何幫助表示贊賞,謝謝!

該系統用於自動檢測圖像文件並將其存儲在“圖像”子文件夾中,對於所有其他文件,將其存儲在“文件”子文件夾中。

這是不正確的,CKFinder從未如此工作。 雖然,您可以使用連接器插件來實現這種行為。

假設我希望所有上傳的圖像都放置在Images:/ ,其他文件應該轉到Files:/

<?php

// plugins/MyPlugin/MyPlugin.php

namespace CKSource\CKFinder\Plugin\MyPlugin;

use CKSource\CKFinder\CKFinder;
use CKSource\CKFinder\Event\BeforeCommandEvent;
use CKSource\CKFinder\Event\CKFinderEvent;
use CKSource\CKFinder\Image;
use CKSource\CKFinder\Plugin\PluginInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MyPlugin implements PluginInterface, EventSubscriberInterface
{
    public function setContainer(CKFinder $app) {}

    public function getDefaultConfig() {
        return [];
    }

    public static function getSubscribedEvents()
    {
        return [
            CKFinderEvent::BEFORE_COMMAND_FILE_UPLOAD => 'handleBeforeFileUpload',
            CKFinderEvent::BEFORE_COMMAND_QUICK_UPLOAD => 'handleBeforeFileUpload'
        ];
    }

    public function handleBeforeFileUpload(BeforeCommandEvent $event) {
        $request = $event->getRequest();

        /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile */
        $uploadedFile = $request->files->get('upload');

        if ($uploadedFile && $uploadedFile->isValid()) {
            $resourceType = 'Files';

            if (Image::isSupportedExtension($uploadedFile->getClientOriginalExtension())) {
                $resourceType = 'Images';
            }

            $request->query->set('type', $resourceType);
            $request->query->set('currentFolder', '/');
        }
    }
}

將以上插件代碼另存為plugins/MyPlugin/MyPlugin.php並在config.php啟用它:

$config['plugins'] = ['MyPlugin'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM