sidus/file-upload-bundle
Composer 安装命令:
composer require sidus/file-upload-bundle
包简介
Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload
README 文档
README
This bundle allows you to define Doctrine entities linked to a virtual filesystem entry through the Flysystem storage layer.
This means that when uploading a file, it will automatically create a corresponding entity in your database matching your resource type.
WARNING: These entities are meant to be associated to other Doctrine entities, not really managed by themselves: If you want to add a title and a description to a file, create a different entity and create an association to the resource.
The upload part is handled by the Oneup Uploader Bundle with very little magic added to it.
This documentation is a work in progress, the bundle is working as is but might require more configuration than what is explained here.
Installation
You will need to include jQuery in your project on your own.
$ composer require sidus/file-upload-bundle
Update your Kernel:
<?php class AppKernel { /** * {@inheritdoc} */ public function registerBundles() { $bundles = [ // ... new Oneup\UploaderBundle\OneupUploaderBundle(), new Oneup\FlysystemBundle\OneupFlysystemBundle(), new Sidus\FileUploadBundle\SidusFileUploadBundle(), // ... ]; // ... } }
Note: The order is very important because we override some parameters frop Oneup.
Additional configuration in your composer.json to expose the jquery-fileupload vendor in public directory of this bundle.
{
"scripts": {
"symfony-scripts": [
// Append this before the clear-cache script
"Sidus\\FileUploadBundle\\Composer\\ScriptHandler::symlinkJQueryFileUpload"
]
}
}
Configuration example for OneUploader using Flysystem with local filesystem.
Note that in order for Sidus/FileUpload to work, the keys for the OneUploader, Flysystem and Sidus must match.
# one uploader oneup_uploader: mappings: document: frontend: blueimp storage: type: flysystem filesystem: oneup_flysystem.document_filesystem max_size: 64000000 oneup_flysystem: adapters: my_adapter: local: directory: '%kernel.root_dir%/../var/data/resources' filesystems: document: adapter: my_adapter
Note the reference in Oneup Uploader to the Flysystem filesystem :
document -> oneup_flysystem.document_filesystem
Now define your uploadable entities, being careful with the configuration keys
sidus_file_upload: configurations: document: # This key will be the entrypoint to any fileupload form widget entity: MyNamespace\AssetBundle\Entity\Document filesystem: document # Optional, defaults to configuration key uploader: document # Optional, defaults to configuration key
Add the upload routes to your routing:
sidus_file_upload: resource: "@SidusFileUploadBundle/Resources/config/routing.yml"
Minimum requirements for your entity
<?php namespace MyNamespace\AssetBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Sidus\FileUploadBundle\Entity\Resource; /** * @ORM\Entity(repositoryClass="Sidus\FileUploadBundle\Entity\ResourceRepository") */ class Document extends Resource { /** * @return string */ public static function getType() { return 'document'; // Must match your mapping key } }
Load the necessary CSS and JS in your layout (there are many way to do this)
'bundles/sidusfileupload/css/fileupload.css'
'bundles/sidusfileupload/vendor/jquery-file-upload/js/jquery.fileupload.js'
'bundles/sidusfileupload/vendor/jquery-file-upload/js/jquery.fileupload-jquery-ui.js'
'bundles/sidusfileupload/vendor/jquery-file-upload/js/jquery.iframe-transport.js'
'bundles/sidusfileupload/js/jquery.fileupload.sidus.js'
To load the widget on document initialization (not exactly the proper way to do it...)
$(document).find('.fileupload-widget').each(function () { $(this).sidusFileUpload(); });
When creating a form, you can simply use the "sidus_resource" type to declare the field as an upload. You will only require to set the "resource_type" options corresponding to the entity you want to use.
Serializer
If you want the Symfony serializer support, you also need to require this:
$ composer require sidus/base-serializer-bundle
You need to enable these bundles in your kernel:
<?php class AppKernel { /** * {@inheritdoc} */ public function registerBundles() { $bundles = [ // ... new Sidus\BaseBundle\SidusBaseBundle(), new Sidus\BaseSerializerBundle\SidusBaseSerializerBundle(), // Then the one documented in the install process new Oneup\UploaderBundle\OneupUploaderBundle(), new Oneup\FlysystemBundle\OneupFlysystemBundle(), new Sidus\FileUploadBundle\SidusFileUploadBundle(), // ... ]; // ... } }
And last, you need to enable serializer support in the configuration:
sidus_file_upload: enable_serializer: true
sidus/file-upload-bundle 适用场景与选型建议
sidus/file-upload-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.05k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「upload」 「doctrine」 「uploader」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sidus/file-upload-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sidus/file-upload-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sidus/file-upload-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An HTML5 upload field for the CMS and frontend forms.
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Smart file uploader for Laravel
Component of cdn uploader for Yii2 framework
Make pimcore migration simple
Laravel Media Popup to upload/view the files
统计信息
- 总下载量: 21.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2016-02-17