Download the PHP package ethsam/symfony-dropzone without Composer

On this page you can find all versions of the php package ethsam/symfony-dropzone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package symfony-dropzone

Symfony Dropzone Bundle

Latest Version on Packagist

Seamless integration of Dropzone.js into Symfony Forms with automatic entity relationship management for drag-and-drop file uploads.

ES

Features

Requirements

Installation

Step 1: Install via Composer

The bundle registers automatically with Symfony Flex. If you're not using Flex, add to config/bundles.php:

Step 2: Include Dropzone.js

Add the following to your base template (e.g., base.html.twig):

That's it! You're ready to use DropzoneType in your forms.

Minimal Example

The shortest thing that actually works, end to end. Four files, nothing optional. The Quick Start below is the same story with the entity relationship spelled out.

1. The file entity. getId(), getFilename() and getSrc() are read by the widget. __toString() is required too: the widget renders the entity itself into a hidden field, and PHP raises a fatal error without it.

2. The form field.

3. The two routes. The upload handler must answer {"id": <int>}: that id is what the widget puts in the hidden field. The remove handler receives the id in the URL.

4. The template. Dropzone.js must already be loaded, see Step 2.

Quick Start

1. Define Your File Entity

2. Define Your Main Entity with Relationship

3. Create a Form Type

4. Create Upload/Remove Handlers

5. Use the Form in Your Template

That's it! The bundle handles everything:

Configuration Options

Option Type Default Description
class string null Required. Entity class for file/attachment objects
multiple bool true Enable multiple file mode; set false for single file (ManyToOne)
maxFiles int 1 Maximum number of files allowed in the dropzone
maxFilesize int|float|null null Maximum file size in MiB, rejected in the browser before upload. null keeps Dropzone's own default. This is a convenience for the user, not a security control: always enforce the limit again in your upload handler
uploadHandler string null Required. Symfony route name for file upload endpoint
removeHandler string null Required. Symfony route name for file removal endpoint
uploadHandlerMethod string "POST" HTTP method for upload requests
removeHandlerMethod string "DELETE" HTTP method for remove requests
choice_src string "src" Entity property name containing file URL/path (getter method: get{PropertyName}())
acceptedFiles string null MIME types accepted (e.g., "image/*,.pdf")
addRemoveLinks bool true Show "Remove" link on file previews
headers array [] Custom HTTP headers sent with requests (e.g., ['Authorization' => 'Bearer TOKEN'])
formData array [] Additional form data sent with upload request
withCredentials int 0 XHR withCredentials setting (0 or 1)
thumbnailWidth int 120 Width of preview thumbnails in pixels
thumbnailHeight int 120 Height of preview thumbnails in pixels
thumbnailMethod string "crop" Thumbnail scaling: "crop" or "contain"
resizeWidth int null Client-side resize width before upload (preserves aspect ratio if only one set)
resizeHeight int null Client-side resize height before upload
resizeMimeType string null Output MIME type after resize (e.g., "image/jpeg")
resizeMethod string "contain" Resize scaling: "crop" or "contain"
filesizeBase int 1024 Base unit for filesize calculations
ignoreHiddenFiles bool true Ignore hidden files in directories
autoProcessQueue bool true Auto-process upload queue on file addition
autoQueue bool true Auto-queue files when added to dropzone
previewsContainer string null CSS selector for custom preview container (e.g., "#my-previews")
required bool true Field is required for form validation

Every option is type checked when the form is built. Passing a value of the wrong type raises an InvalidOptionsException instead of being written into the page.

JavaScript Events

The widget dispatches DOM events on the dropzone element, so you can extend the behaviour without overriding the template or injecting JavaScript from PHP. Events bubble, so listening on document is enough.

Event Fired when event.detail
symfony-dropzone:init The Dropzone instance is ready { dropzone, config }
symfony-dropzone:sending Just before a file is uploaded { dropzone, file, xhr, formData }
symfony-dropzone:removedfile After a file is removed { file }

The symfony-dropzone: prefix is not an accident. Dropzone.js 6 dispatches its own DOM events named dropzone:sending, dropzone:success and so on, with a detail of {args: [...]}. Those are still available and unaffected; the events above are the bundle's, with a named detail, and they work the same on Dropzone 5 which has no DOM events at all.

Sending an extra field with each upload

The formData option covers values known when the form is built, in PHP. It cannot carry anything the user types or picks on the page, because uploads are sent by AJAX long after the page was rendered. That is what symfony-dropzone:sending is for.

Say the same form has a category selector, and the upload handler needs to know which category was selected at the moment the file was dropped:

The handler reads it like any other posted field:

Treat that value as user input, exactly like the rest of the request. The browser decides what it sends, so validate it server side.

A value that has no field at all, computed in the browser, works the same way:

Reaching the Dropzone instance itself, for anything the options do not cover:

The symfony-dropzone:init listener has to be registered before the widget renders, typically in the page head or in a script loaded with defer. The other events fire on user interaction, so they can be bound at any time.

File Entity Requirements

Your file/attachment entity must implement:

Example minimal entity:

How It Works

Architecture Overview

  1. Form Type Registration: DropzoneType extends Symfony's form system
  2. Hidden Fields: For multiple files: a CollectionType with hidden inputs; for single: an EntityType field
  3. Twig Template: Renders Dropzone.js widget with JavaScript configuration
  4. Upload Flow:
    • User drags files or clicks to select
    • Dropzone.js sends each file to your uploadHandler route via AJAX
    • Handler persists entity to database, returns {"id": <int>}
    • Bundle stores file ID in hidden form field
  5. Form Submission: Hidden field values are collected
  6. Data Transformation: DropzoneTransformer converts IDs back to entity objects via Doctrine
  7. Persistence: Form submission handles OneToMany/ManyToOne relationships automatically

File Removal Flow

  1. User clicks "Remove" link on file preview
  2. Dropzone.js sends DELETE (or POST) to removeHandler route
  3. Handler deletes entity, returns {"id": <int>}
  4. Widget removes preview from DOM

Step 2 is what actually detaches the file, and your handler is expected to make the removal effective on its own. Do not count on the form submission that follows to finish the job: files that were already attached when the page was rendered are also listed in hidden fields written by Symfony, which the widget does not remove. Their ids are still submitted after the preview disappears. If your remove handler only unlinks the file instead of deleting it, that submission will link it back.

Examples

Basic Multiple File Upload

Single File Upload (ManyToOne)

Image-Only with Custom Dimensions

With Custom Headers (API Authentication)

Custom Preview Container

With Custom Form Data

Your upload handler receives this in $request->request->all():

Security

How the widget renders

The widget never builds JavaScript out of your data. Everything the browser needs, including stored filenames, is serialised to JSON inside an HTML attribute and read back with JSON.parse. The inline <script> is a constant block of code: it is byte for byte identical whatever your database contains.

This matters because filenames are supplied by whoever uploads a file. Versions up to and including 2.0.0 interpolated them straight into the script, where Twig's HTML escaping does not protect a JavaScript string context. See SECURITY.md for the details and for how to report an issue.

If you maintain a copy of dropzone.html.twig in your own templates/bundles/SymfonyDropzoneBundle/, that copy is what Symfony renders, and it is still on the old behaviour. Delete it or port your changes over.

What is still your responsibility

Upgrading from 2.0

No option was renamed or removed, and no application code has to change.

Upgrading from v1

If you're upgrading from the original emr-dev/symfony-dropzone:

Migration example:

The API and functionality remain the same.

Differences from symfony/ux-dropzone

Feature ethsam/symfony-dropzone symfony/ux-dropzone
Entity relationships Full OneToMany/ManyToOne support None; form values only
Data transformation Automatic ID → Entity Manual
Multiple files Built-in with CollectionType Not ideal
Edit mode pre-population Yes; shows existing files Manual templating
Upload handler Simple route + JSON response Requires UX component
File removal Built-in DELETE handler Manual
Dropzone config Full access to all options Limited
Learning curve Minimal; standard Symfony forms Moderate; UX paradigm
Maintenance Active Official but UX-focused

Summary: Use ethsam/symfony-dropzone for entity-driven file management; use symfony/ux-dropzone if you need tight Stimulus integration or prefer the UX paradigm.

Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/your-feature
  3. Commit your changes: git commit -m "feat: add your feature"
  4. Push to the branch: git push origin feat/your-feature
  5. Open a Pull Request

For bug reports or feature requests, please open an issue.

License

This bundle is licensed under the MIT License. See LICENSE for details.

Originally forked from emr-dev/symfony-dropzone.

Credits


All versions of symfony-dropzone with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
doctrine/orm Version ^2.12 || ^3.0
symfony/config Version ^5.4 || ^6.0 || ^7.0
symfony/dependency-injection Version ^5.4 || ^6.0 || ^7.0
symfony/doctrine-bridge Version ^5.4 || ^6.0 || ^7.0
symfony/form Version ^5.4 || ^6.0 || ^7.0
symfony/http-kernel Version ^5.4 || ^6.0 || ^7.0
symfony/options-resolver Version ^5.4 || ^6.0 || ^7.0
symfony/twig-bundle Version ^5.4 || ^6.0 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ethsam/symfony-dropzone contains the following files

Loading the files please wait ...