faparicior/far-symfony2-jquery-upload
Composer 安装命令:
composer require faparicior/far-symfony2-jquery-upload
包简介
Integrates JqueryUpload into Symfony2 with OneUpFlySystem
README 文档
README
This bundle adds symfony2 integration to the BlueImp/Jquery Upload Plugin using 1up-lab/OneUpFlySystemBundle filesystem abstraction layer.
The project faparicior/FARSymfony2UploadDemo is a demo to test this Bundle.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require faparicior/far-symfony2-jquery-upload "~1"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new faparicior\FARSymfony2UploadBundle\FARSymfony2UploadBundle(), ); // ... } // ... }
Step 3: Configure the Bundle
- Add this lines in the
app/config/routing.yml
far_symfony2_upload: resource: "@FARSymfony2UploadBundle/Controller/" type: annotation prefix: "/farupload"
- Add the config necessary for the bundle in
app/config/config.yml
far_symfony2_upload: prefix: "farupload" temp_path: "%kernel.root_dir%/../web/tmp" thumbnail_directory_prefix: "thumbnails" thumbnail_driver: "gd" thumbnail_size: "80x80" max_file_size: 100000 max_files_upload: 2 file_extensions_allowed: ["jpg", "png", "gif"] local_filesystem: "local_filesystem" remote_filesystem: "remote_filesystem"
-
Enable the 1up-lab/OneUpFlySystemBundle
-
Add the config necessary for the OneUpFlySystem bundle in
app/config/config.yml
oneup_flysystem: adapters: local_adapter: local: directory: %kernel.root_dir%/../web/tmp writeFlags: ~ linkHandling: ~ remote_adapter: local: directory: %kernel.root_dir%/../web/images writeFlags: ~ linkHandling: ~ filesystems: my_filesystem: adapter: local_adapter mount: local_filesystem remote_filesystem: adapter: remote_adapter mount: remote_filesystem
- You can see the new routes added to your development.
$ php app/console debug:router
farsymfony2upload_default_upload POST ANY ANY /farupload/upload/{id_session}
farsymfony2upload_default_delete POST|DELETE ANY ANY /farupload/tmp/{php_session}/{id_session}/{image}_{action}
Usage
In the upload javascript action
Your javascript development needs an UID that identifies the upload. The bundle uses the php_session and the UID to generate the temporary directory structure.
In the save symfony2 action
This is te example of a save action for symfony2.
With the php_session and the UID that stores the id_session variable, you can get
the files involved in the upload.
The getListFilesLocal function returns an array of files like this:
{
"files": [
{
"type": "file",
"timestamp": 1451316072,
"size": 66664,
"pathOrig": "d0i8nvm9p9h3v9k08vn8jl1qs7/123/60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"dirnameOrig": "d0i8nvm9p9h3v9k08vn8jl1qs7/123",
"basenameOrig": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"extensionOrig": "jpeg",
"filenameOrig": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original",
"pathDest": "d0i8nvm9p9h3v9k08vn8jl1qs7/123/60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg"
"dirnameDest": "d0i8nvm9p9h3v9k08vn8jl1qs7/123"
"basenameDest": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"extensionDest": "jpeg",
"filenameDest": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original",
}
]
}
The setListFilesPathRemote function returns an array of files that
establishes origin and destination to filesystems:
{
"files": [
{
"type": "file",
"timestamp": 1451316072,
"size": 66664,
"pathOrig": "d0i8nvm9p9h3v9k08vn8jl1qs7/123/60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"dirnameOrig": "d0i8nvm9p9h3v9k08vn8jl1qs7/123",
"basenameOrig": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"extensionOrig": "jpeg",
"filenameOrig": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original",
"pathDest": "123/60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"dirnameDest": "123",
"basenameDest": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"extensionDest": "jpeg",
"filenameDest": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original",
}
]
}
The syncFilesLocalRemote copy files from temporary to definitive storage.
This function returns an array with the results. Include properties that
informs the duplicated or rewrited files.
{
"files": [
{
"type": "file",
"timestamp": 1451316072,
"size": 66664,
"pathOrig": "d0i8nvm9p9h3v9k08vn8jl1qs7/123/60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"dirnameOrig": "d0i8nvm9p9h3v9k08vn8jl1qs7/123",
"basenameOrig": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"extensionOrig": "jpeg",
"filenameOrig": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original",
"pathDest": "123/60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"dirnameDest": "123",
"basenameDest": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original.jpeg",
"extensionDest": "jpeg",
"filenameDest": "60aca821-0104-405c-8a3f-a1ac8a0041ff-original",
"saved": true,
"duplicated": true
}
]
}
The deleteFilesLocal cleans the temporary files. And returns the same
array that syncFilesLocalRemote.
You can modify pathDest, dirnameDest, basenameDest, extensionDest, filenameDest elements
in the array before send to call syncFilesLocalRemote to save the files in another destination.
/** * @Route("/save/{id_session}") * @Method("POST") * * @param string $id_session * * @return JsonResponse */ public function saveAction($id_session) { $php_session = $this->get('session')->getId(); $FARUpload = $this->get('far_symfony2_upload_bundle.far_symfony2_upload_lib.service'); $files = $FARUpload->getListFilesLocal($php_session, $id_session); $files = $FARUpload->setListFilesPathRemote($files, $id_session); $files = $FARUpload->syncFilesLocalRemote($files, true); $files = $FARUpload->deleteFilesLocal($files); return new JsonResponse(array('files' => $files)); }
faparicior/far-symfony2-jquery-upload 适用场景与选型建议
faparicior/far-symfony2-jquery-upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Bundle JqueryUpload FlySystem Symfony2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 faparicior/far-symfony2-jquery-upload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 faparicior/far-symfony2-jquery-upload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 faparicior/far-symfony2-jquery-upload 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Backblaze B2 Cloud Storage for Laravel 5. Original by Paul Olthof (@hpolthof) continued by @bringyourownideas
Virtual Filesystem Storage Adapter for Laravel
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
统计信息
- 总下载量: 48
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-28