我使用的是FMElfinderBundle v.5(由于某些原因,我不能使用最新版本)与Symfony 2.8.12。我遵循文档,它工作得很好,直到有要求允许上传大文件(高达20MB)。我将upload_max_size参数更改为20M,这是可以的,但是在上传文件时,文件被分割为2MB的块,elfinder试图将它们存储在临时目录中。问题是,它无法进入那里。它不从虚拟主机定义中读取设置,它总是使用系统临时文件夹。
阅读文档,我发现可以使用两个参数来配置elfinder temp dir - upload_temp_path
和common_temp_path
。但我没能设置好它们。每次我运行在PHPStorm控制台命令s cache: 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
谁可以帮助我,如何设置临时目录?
好的,一些详细信息:
我从ElFinder bundle中取出ElFinderConfigurationReader并将其保存到我的项目中,名称为ElFinderConfigurationCustomReader。然后将这个类定义为服务:
service.custom_fm_elfinder.configurator:
class: CSBNSVJBundleComponentElFinderElFinderConfigurationCustomReader
arguments: ['%fm_elfinder%', '@request_stack', '@service_container', '%elfinder_temporary_path%']
变量elfinder_temporary_path在parameters.yml中设置。
配置。我设置了我自己的配置阅读器:
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;
}
好的,我找到解决办法了。有必要制作自己的自定义配置阅读器,并替换原来的阅读器。配置类必须实现ElFinderConfigurationProviderInterface。详情请参阅[https://github.com/helios-ag/FMElfinderBundle/blob/master/Resources/doc/advanced-configuration.md#custom-configuration-provider][1]