anatoliynyatin/far-symfony2-jquery-upload 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

anatoliynyatin/far-symfony2-jquery-upload

Composer 安装命令:

composer require anatoliynyatin/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

  1. Add this lines in the app/config/routing.yml
far_symfony2_upload:
    resource: "@FARSymfony2UploadBundle/Controller/"
    type:     annotation
    prefix:   "/farupload"
  1. 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"
  1. Enable the 1up-lab/OneUpFlySystemBundle

  2. 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
  1. 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));
}

anatoliynyatin/far-symfony2-jquery-upload 适用场景与选型建议

anatoliynyatin/far-symfony2-jquery-upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 387 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Bundle JqueryUpload FlySystem Symfony2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 anatoliynyatin/far-symfony2-jquery-upload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 anatoliynyatin/far-symfony2-jquery-upload 我们能提供哪些服务?
定制开发 / 二次开发

基于 anatoliynyatin/far-symfony2-jquery-upload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 387
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-03