intaro/file-uploader-bundle

Symfony2 组件,旨在简化文件上传过程

安装次数: 348,474

依赖者: 0

建议者: 0

安全: 0

星标: 3

关注者: 16

分支: 3

公开问题: 2

类型:symfony-bundle

v2.1.0 2023-01-09 12:19 UTC

README

关于

这是一个 Symfony2 组件。该组件的目的是简化文件上传过程。文件上传到临时文件夹后,该组件会将文件移动到存储位置。

支持几种存储类型

  • 本地文件系统
  • Amazon S3

安装

在 composer.json 文件中添加组件依赖

  {
      "require": {
          "intaro/file-uploader-bundle": "dev-master",
      }
  }

在 AppKernel 中注册

  // app/AppKernel.php
  
  class AppKernel extends SaasKernel
  {
      public function registerBundles()
      {
          $bundles = array(
              ...
              new Intaro\FileUploaderBundle\IntaroFileUploaderBundle(),
          );
      }
  }

使用 composer 安装

$ composer update intaro/file-uploader-bundle

使用方法

在配置中

  # app/config/config.yml
  
  intaro_file_uploader:
    uploaders:
        local:
            image:
                path: http://www.app.local/images/
                create: true
                allowed_types: ['image/jpeg', 'image/png', 'image/gif']
            document:
                directory: path/to/another/attach/dir
                create: true
                allowed_types: ['application/pdf', 'application/rtf', 'application/vnd.ms-office']
        aws_s3:
            video:
                service_id: aws.client_service_name
                path: https://s3-us-west-2.amazonaws.com/bucket-name/iamges/
                bucket_name: some_bucket
                options:
                    create: true
                    acl: public-read

在代码中

public function uploadAction()
{
    $files = $this->getRequest()->files->get('file');
    
    $this->get('intaro.video_uploader')->upload($file);
}