繁体   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