FMELfinderBundle 5 - 如何设置用于上传的临时文件夹

FMElfinderBundle 5 - how to set temp folder for upload

我在 Symfony 2.8.12 中使用 FMELfinderBundle v.5(由于某些原因我不能使用最新版本)。我遵循了文档并且它工作正常,直到有允许上传大文件(最多 20MB)的请求。我将 upload_max_size 参数更改为 20M 并且没问题,但是在上传过程中文件被拆分为 2MB 块并且 elfinder 尝试将它们存储在临时目录中。问题是,它无法访问那里。它不从虚拟主机定义中读取设置,它始终使用系统临时文件夹。

阅读文档我发现可以使用两个参数来配置 elfinder 临时目录 - upload_temp_pathcommon_temp_path。但是我没有设置它们的运气。每次我 运行 在 PHPStorm 控制台命令的缓存中:clear --no-warmup 我得到 InvalidConfigurationException.

我试图将参数放在 fm_elfinder 键下的配置结构中的其他地方,但仍然是相同的异常。

这是我在config.yml中的配置:


    fm_elfinder:
        instances:
            default:
                locale: %locale%
                editor: ckeditor
                fullscreen: true
                theme: smoothness
                include_assets: true
                relative_path: false
                connector:
                    roots:
                        uploads:
                            driver: LocalFileSystem
                            path: uploads
                            upload_max_size: 20M

任何人都可以帮助我,如何设置临时目录?

好的,我找到了解决方案。有必要制作您自己的自定义配置 reader 并替换原来的配置。配置 class 必须实现 ElFinderConfigurationProviderInterface。有关详细信息,请参阅 [https://github.com/helios-ag/FMElfinderBundle/blob/master/Resources/doc/advanced-configuration.md#custom-configuration-provider][1]

好的,一些详细信息:

我从 ElFinder 包中获取了 ElFinderConfigurationReader,并将其保存到我的项目中,名称为 ElFinderConfigurationCustomReader。然后这个 class 我定义为服务:

service.custom_fm_elfinder.configurator:
    class: CSBN\SVJBundle\Component\ElFinder\ElFinderConfigurationCustomReader
    arguments: ['%fm_elfinder%', '@request_stack', '@service_container', '%elfinder_temporary_path%']

变量 elfinder_temporary_path 在 parameters.yml 中设置。

在config.yml我设置了我自己的配置reader:

fm_elfinder:
configuration_provider: service.custom_fm_elfinder.configurator

在我新创建的文件 ElFinderConfigurationCustomReader 中,我只是在方法 getConfiguration 中添加了一行:

$options['uploadTempPath'] = $this->temporaryPath;

取自构造函数中的服务参数。

希望对您有所帮助。

编辑:全功能复制:

/**
 * @param $instance
 *
 * @return array
 */
public function getConfiguration($instance)
{
    $request                = $this->requestStack->getCurrentRequest();
    $efParameters           = $this->parameters;
    $parameters             = $efParameters['instances'][$instance];
    $options                = array();
    $options['corsSupport'] = $parameters['cors_support'];
    $options['debug']       = $parameters['connector']['debug'];
    $options['bind']        = $parameters['connector']['binds'];
    $options['plugins']     = $parameters['connector']['plugins'];
    $options['uploadTempPath'] = $this->temporaryPath;
    $options['roots']       = array();

    foreach ($parameters['connector']['roots'] as $parameter) {
        $path       = $parameter['path'];
        $homeFolder = $request->attributes->get('homeFolder');
        if ($homeFolder !== '') {
            $homeFolder = '/'.$homeFolder.'/';
        }

        $driver = $this->container->has($parameter['driver']) ? $this->container->get($parameter['driver']) : null;

        $driverOptions = array(
            'driver'            => $parameter['driver'],
            'service'           => $driver,
            'glideURL'          => $parameter['glide_url'],
            'glideKey'          => $parameter['glide_key'],
            'plugin'            => $parameter['plugins'],
            'path'              => $path.$homeFolder, //removed slash for Flysystem compatibility
            'startPath'         => $parameter['start_path'],
            'URL'               => $this->getURL($parameter, $request, $homeFolder, $path),
            'alias'             => $parameter['alias'],
            'mimeDetect'        => $parameter['mime_detect'],
            'mimefile'          => $parameter['mimefile'],
            'imgLib'            => $parameter['img_lib'],
            'tmbPath'           => $parameter['tmb_path'],
            'tmbPathMode'       => $parameter['tmb_path_mode'],
            'tmbUrl'            => $parameter['tmb_url'],
            'tmbSize'           => $parameter['tmb_size'],
            'tmbCrop'           => $parameter['tmb_crop'],
            'tmbBgColor'        => $parameter['tmb_bg_color'],
            'copyOverwrite'     => $parameter['copy_overwrite'],
            'copyJoin'          => $parameter['copy_join'],
            'copyFrom'          => $parameter['copy_from'],
            'copyTo'            => $parameter['copy_to'],
            'uploadOverwrite'   => $parameter['upload_overwrite'],
            'uploadAllow'       => $parameter['upload_allow'],
            'uploadDeny'        => $parameter['upload_deny'],
            'uploadMaxSize'     => $parameter['upload_max_size'],
            'defaults'          => $parameter['defaults'],
            'attributes'        => $parameter['attributes'],
            'acceptedName'      => $parameter['accepted_name'],
            'disabled'          => $parameter['disabled_commands'],
            'treeDeep'          => $parameter['tree_deep'],
            'checkSubfolders'   => $parameter['check_subfolders'],
            'separator'         => $parameter['separator'],
            'timeFormat'        => $parameter['time_format'],
            'archiveMimes'      => $parameter['archive_mimes'],
            'archivers'         => $parameter['archivers'],
        );

        if ($parameter['volume_id'] > 0) {
            $driverOptions['id'] = $parameter['volume_id'];
        }

        if (!$parameter['show_hidden']) {
            $driverOptions['accessControl'] = array($this, 'access');
        };

        $options['roots'][] = array_merge($driverOptions, $this->configureDriver($parameter));
    }

    return $options;
}