承接 sbyaute/symfony-dropzone 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sbyaute/symfony-dropzone

Composer 安装命令:

composer require sbyaute/symfony-dropzone

包简介

Symfony Form Type

README 文档

README

Étend le composant SymfonyForm. Ajoute le nouveau type de formulaire DropzoneType.

Installation

composer require sbyaute/symfony-dropzone

Assets

Ajoutez la bibliothèque dropzone à votre projet dans le template

{% block stylesheets %}
    {{ parent() }}
    <link rel="stylesheet" href="{{ asset('assets/dropzone/style/dropzone.css') }}">
    <style>
        .dropzone {
        min-height:25px;
        padding:5px 5px 5px
    }
        .dz-button {
        width:270px;
    }
    </style>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script src="{{ asset('assets/dropzone/js/dropzone-min.js') }}"></script>
{% endblock %}```

## Usage
```php
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{ 

    // fichiers is OneToMany
    $builder->add('fichiers', DropzoneType::class, [
        'class' => Fichier::class,
        'maxFilesize' => 8,  // Taille max du fichier en MB
        'maxFiles' => 6,        // Nb max de fichiers téléchargeables
        'uploadHandler' => 'uploadHandler', // route pour le chargement
        'removeHandler' => 'removeHandler', // route pour la suppression
        'downloadHandler' => 'downloadHandler', // route pour le téléchargement
        'previewsContainer' => true,        // Si true, sort la previsu de la dropzone (pas d'image)
        'choice_src' => 'src',              // Champ de l'entité contenant le nom du fichier sur le serveur
        'acceptedFiles' => '',        // Liste des types de fichiers autorisés ('.zip, .doc, .xls')
        'dictDefaultMessage' => 'Cliquez ou glissez/déposez vos fichiers ici ...',
        'dictRemoveFileConfirmation' => 'Etes-vous sûr ?', // active la confirmation de suppression
        'required' => false,
    ]);
}

Exemples route uploadHandler/removeHandler

/**
     * @Route("/uploadhandler", name="uploadHandler")
     */
    public function uploadhandler(Request $request, ImageUploader $uploader) { 
        $doc = $uploader->upload($request->files->get('file'));  
        $file = new File(); 
        $file->setSrc($doc['src']);
        ...

        $this->getDoctrine()->getManager()->persist($file);
        $this->getDoctrine()->getManager()->flush();
        return new JsonResponse($file);
    }


    /**
     * @Route("/removeHandler/{id}", name="removeHandler")
     */
    public function removeHandler(Request $request,File $file = null) {
        $this->getDoctrine()->getManager()->remove($file);
        $this->getDoctrine()->getManager()->flush();
        return new JsonResponse(true);
    }

Options

Name Default Description
class null File Entity
choice_src "src" property that contains src
uploadHandler null Symfony route name for upload
removeHandler null Symfony route name for remove
multiple true Set to false if you have a one to one relationship
maxFiles 1 If not null defines how many files this Dropzone handles.
addRemoveLinks true If true, this will add a link to every file preview to remove or cancel (if already uploading) the file.
headers [] An optional object to send additional headers to the server. Headers is array. Eg: ['Authorization' => 'Bearer XXXXXX']
formData [] Additional data that will be sent to FormData. Eg: ['key' => 'value']
uploadHandlerMethod "POST" Can be changed to "PUT" if necessary.
removeHandlerMethod "DELETE" Can be changed to "POST" if necessary.
withCredentials 0 Will be set on the XHRequest.
thumbnailWidth 120 If null, the ratio of the image will be used to calculate it.
thumbnailHeight 120 The same as thumbnailWidth. If both are null, images will not be resized.
thumbnailMethod "crop" How the images should be scaled down in case both, thumbnailWidth and thumbnailHeight are provided. Can be either contain or crop.
resizeWidth null If set, images will be resized to these dimensions before being uploaded. If only one, resizeWidth or resizeHeight is provided, the original aspect ratio of the file will be preserved.
resizeHeight null See resizeWidth.
resizeMimeType null The mime type of the resized image (before it gets uploaded to the server). If null the original mime type will be used. To force jpeg, for example, use image/jpeg. See resizeWidth for more information.
resizeMethod "contain" How the images should be scaled down in case both, resizeWidth and resizeHeight are provided. Can be either contain or crop.
filesizeBase 1024 -
ignoreHiddenFiles true Whether hidden files in directories should be ignored.
acceptedFiles null Eg.: image/*,application/pdf,.psd
autoProcessQueue true If false, files will be added to the queue but the queue will not be processed automatically. This can be useful if you need some additional user input before sending files (or if you want want all files sent at once). If you're ready to send the file simply call myDropzone.processQueue().
autoQueue true If false, files added to the dropzone will not be queued by default. You'll have to call enqueueFile(file) manually.
previewsContainer null Defines where to display the file previews – if null the Dropzone element itself is used. Can be a CSS selector.

License MIT

sbyaute/symfony-dropzone 适用场景与选型建议

sbyaute/symfony-dropzone 是一款 基于 Twig 开发的 Composer 扩展包,目前已累计 792 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 sbyaute/symfony-dropzone 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Twig

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-26