onnov/fm-elfinder-bundle

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

资助包维护!
paypal.me/heliosag

安装: 243

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 127

类型:symfony-bundle

v0.0.2 2023-06-19 14:12 UTC

This package is auto-updated.

Last update: 2024-09-19 16:56:19 UTC


README

FMElfinderBundle

在Symfony中集成ElFinder

代码质量保证

自豪地使用PhpStorm开发

elFinder是一个开源的Web文件管理器,使用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资源复制到public文件夹

  bin/console elfinder:install

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

在kernel中启用扩展包(与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步:配置您的application's 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)
  • 编辑器 - 决定渲染哪个模板,以与所见即所得的Web编辑器兼容,当前支持以下选项:"ckeditor"(与FOSCKEditorBundle或TrsteelCkeditorBundle一起使用),"fm_tinymce"(用于tinymce4,与FMTinyMCEBundle一起使用),"form"(用于表单类型),"simple"(独立使用),"custom"(自定义模板)。如何配置CKEDitor和TinyMCE与该捆绑包一起使用,将在本文档中进一步解释。
  • editor_template - 定义当编辑器设置为"custom"时渲染的模板。
  • connector - 定义elfinder根目录选项的根节点。
  • roots - 定义反映您项目中的目录的"虚拟目录"。
  • path_prefix - 在启用relative_path时的路径前缀,默认为斜杠('/')
  • show_hidden - 显示以.(点)开头的文件和文件夹
  • driver - 驱动类型,LocalFileSystem,Dropbox,FTP
  • volume_id - (可选)可以在挂载卷时强制使用卷ID(默认自动递增)。如果提供,则必须是一个大于0的整数。
  • alias - 目录别名
  • path - 包含文件的目录
  • upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
  • upload_deny: ['all']
  • upload_max_size: 2M

您可以在这里查看roots选项的完整列表。要使用它们,请将驼峰命名法的选项名称转换为snake_case名称。

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

您可以通过实例配置设置多个上传根目录。

如果您已经使用/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}: {index of the connector}
multi_home_folder: true
folder_separator: {one char other of /}

示例

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 }