alxishin/fm-elfinder-bundle

ElFinder 扩展包,将 ElFinder 文件管理器添加到您的 Symfony 项目中

安装: 214

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 127

类型:symfony-bundle

10.1.0.3 2021-06-23 09:05 UTC

README

ElFinder 在 Symfony 中的集成

代码质量保证

elFinder 是一个基于 JavaScript 和 jQuery UI 的开源网络文件管理器。它的设计灵感来源于 Mac OS X 操作系统中使用的 Finder 程序的简洁性和便捷性。

推荐搭配使用的扩展包

目录

安装

步骤 1:安装

对于 Symfony Flex 安装,您需要启用社区食谱

  composer config extra.symfony.allow-contrib true

安装

  composer require helios-ag/fm-elfinder-bundle

将 elfinder 资产复制到公共文件夹

  bin/console elfinder:install

步骤 2:启用扩展包(可选)

在内核中启用扩展包(与 symfony flex 一起使用时不需要)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FM\ElfinderBundle\FMElfinderBundle(),
    );
}

步骤 3:导入 FMElfinderBundle 路由文件

# app/config/routing.yaml
elfinder:
     resource: "@FMElfinderBundle/Resources/config/routing.yaml"

步骤 4:配置您的应用程序的 security.yaml

使用 access_control 保护 ElFinder

# app/config/security.yaml
security:

    //....
    access_control:
        - { path: ^/efconnect, role: ROLE_USER }
        - { path: ^/elfinder, role: ROLE_USER }

基本配置

将配置选项添加到您的 config.yaml

fm_elfinder:
    #assets_path: / # default is /assets, this is where css/js elfinder files are
    instances:
        default:
            locale: '%locale%' # defaults to current request locale
            editor: ckeditor # other options are tinymce, tinymce4, fm_tinymce, form, simple, custom
            relative_path: false #default true, will produce absolute urls to specified file(s)
            #editor_template: custom template for your editor # default null
            #path_prefix: / # for setting custom assets path prefix, useful for non vhost configurations, i.e. http://127.0.0.1/mysite/
            #fullscreen: true|false # default is true, applies to simple and ckeditor editors
            #theme: smoothness # jquery theme, default is 'smoothness'
            #visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg'] # only show these mime types, defaults to show all
            connector:
                #debug: true|false # defaults to false
                roots:       # at least one root must be defined, defines root filemanager directories
                    uploads:
                        #show_hidden: true|false # defaults to false, hides dotfiles
                        driver: LocalFileSystem
                        path: uploads
                        upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
                        upload_deny: ['all']
                        upload_max_size: 2M # also file upload sizes restricted in php.ini
                        #attributes: example of setting attributes permission
                        #    - { pattern: '/(.*?)/', read: true, write: false, locked: true }
  • default - elfinder 的实例,可以用于定义多个 ElFinder 配置,允许为项目中的不同类型的 WYSIWYG 编辑器同时进行配置
  • path - 定义 web/ 目录内文件的根目录,默认为 "uploads"。请确保为此目录设置正确的读写和所有者权限。
  • url - 要添加到图像路径的前缀 URL,用于显示。可以是 absoluterelative。如果是绝对路径,可以使用 {homeFolder} 字符串作为占位符,它将被自动替换。如果是相对路径,它将与应用程序的基础 URL 前缀。如果为空,URL 将是基础 URL,后缀为 'path' 参数的值
  • driver - 可以是 LocalFileSystem、FTP 或 MySQL、Flysystem、S3 等,请参阅 FM\ElfinderBundle\DependencyInjection\Configuration 类
  • locale - 区域设置决定了 ElFinder 将使用哪种语言来翻译用户界面,默认为当前请求的区域设置
  • cors_support - 允许处理跨域响应(默认为 false)
  • editor - 确定要渲染的模板,以便与 WYSIWYG 网页编辑器兼容,目前支持以下选项:"ckeditor"(用于 FOSCKEditorBundle 或 TrsteelCkeditorBundle)、"fm_tinymce"(用于 tinymce4,与 FMTinyMCEBundle 一起使用)、"form"(用于表单类型)、"simple"(独立使用)和 "custom"(自定义模板)。如何配置 CKEDitor 和 TinyMCE 以与该扩展包一起使用,将在本文件的后续部分进行说明。
  • editor_template - 当编辑器设置为 "custom" 时,定义要渲染的模板。
  • connector - 定义 elfinder 根目录选项的根节点。
  • roots - 定义 "虚拟目录",它反映了您项目中的目录。
  • path_prefix - 使用 relative_path 启用时,路径前缀,默认为斜杠 ('/')
  • show_hidden - 显示以 .(点)开头的文件和文件夹
  • 驱动器 - 驱动器类型,LocalFileSystem,Dropbox,FTP
  • volume_id - (可选) 在挂载卷时可以用来强制指定卷ID(默认自动递增)。如果提供,它必须是一个大于0的整数。
  • alias - 目录别名
  • path - 包含文件的目录
  • upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
  • upload_deny: ['all']
  • upload_max_size: 2M

您可以在此处查看完整的根选项列表。要使用它们,请将驼峰命名法选项名称转换为蛇形命名法。

通过实例使用多个上传文件夹

您可以通过实例配置设置多个上传根文件夹。

如果您已将实例配置为/uploads路径,您可以在访问实例URL时提供一个附加文件夹作为主文件夹(例如,用于多用户应用程序):

/elfinder/{instance}/{homeFolder}/efconnect/{instance}/{homeFolder}

例如,访问/elfinder/acmeInstance/bob URL将打开elfinder,以/uploads/bob作为根目录,其中只包含Bob的文件。

然后,访问/elfinder/acmeInstance/alice URL将重用您的实例,但将以/uploads/alice文件夹作为根目录打开elfinder,其中只包含Alice的文件。

要使用此功能,您必须在URL中提供实例名称,并确保在主文件夹上设置适当的读写权限。

注意:此功能仅在LocalFileSystem驱动程序中可用。

如果我想使用多个主文件夹呢?

是的,您可以通过在fm_elfinder.yaml中的此配置来实现:

where_is_multi: {connector}: {连接器的索引} multi_home_folder: true folder_separator: {一个字符的其他/}

示例

fm_elfinder:
    instances:
        default:
            locale: fr # defaults to current request locale
            editor: ckeditor # other options are tinymce, tinymce4, fm_tinymce, form, simple, custom
            #editor_template: custom template for your editor # default null
            #path_prefix: https:/// # for setting custom assets path prefix, useful for non vhost configurations, i.e. http://127.0.0.1/mysite/
            fullscreen: false # default is true, applies to simple and ckeditor editors
            where_is_multi:
                roots: 0
            multi_home_folder: true
            folder_separator: "|"
            #theme: smoothness # jquery theme, default is 'smoothness'
            #visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg'] # only show these mime types, defaults to show all
            connector:
                #debug: true|false # defaults to false
                roots:       # at least one root must be defined, defines root filemanager directories
                    uploads:
                        #show_hidden: true|false # defaults to false, hides dotfiles
                        driver: LocalFileSystem
                        path: "/var"
                        alias: Bibliothèque générale
                        upload_allow: ['all']
                        #upload_deny: ['all']
                        upload_max_size: 500M # also file upload sizes restricted in php.ini
                        attributes:
                            - {pattern: '..', read: true, write: true, locked: false}
                        #attributes: example of setting attributes permission
                        #    - { pattern: '/(.*?)/', read: true, write: false, locked: true }