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.
Download ethsam/symfony-dropzone
More information about ethsam/symfony-dropzone
Files in ethsam/symfony-dropzone
Package symfony-dropzone
Short Description Symfony Form Type integrating Dropzone.js for drag-and-drop file uploads with entity relationship support
License MIT
Homepage https://github.com/ethsam/symfony-dropzone
Informations about the package symfony-dropzone
Symfony Dropzone Bundle
Seamless integration of Dropzone.js into Symfony Forms with automatic entity relationship management for drag-and-drop file uploads.
ES
Features
- Drag-and-drop file uploads — Powered by Dropzone.js
- Entity relationship support — Automatically manage OneToMany and ManyToOne associations
- Built-in data transformation — IDs to entities via Doctrine ORM
- Pre-populated edit forms — Show existing files in edit mode
- Fully configurable — Dropzone.js options exposed in form builder
- Single or multiple files — Control upload mode per form field
- Custom upload/remove handlers — Route-based endpoints with JSON responses
- Image resizing — Client-side image processing before upload
- Flexible authentication — Custom headers for API integration
- Symfony Flex compatible — Automatic bundle registration
Requirements
- PHP: ≥8.1
- Symfony: 5.4, 6.x, 7.x
- Doctrine ORM: 2.12+
- Dropzone.js: 6.0+ (included via CDN)
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.
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:
- Dropzone.js widget rendering
- File upload via AJAX
- File ID storage in hidden fields
- Entity relationship transformation on form submission
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 |
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 |
File Entity Requirements
Your file/attachment entity must implement:
getId(): ?int— Returns the unique identifiergetFilename(): string— Returns the filename for display- Getter for
choice_srcproperty — By defaultgetSrc(): string, returns the file URL/path for thumbnail display
Example minimal entity:
How It Works
Architecture Overview
- Form Type Registration —
DropzoneTypeextends Symfony's form system - Hidden Fields — For multiple files: a
CollectionTypewith hidden inputs; for single: anEntityTypefield - Twig Template — Renders Dropzone.js widget with JavaScript configuration
- Upload Flow:
- User drags files or clicks to select
- Dropzone.js sends each file to your
uploadHandlerroute via AJAX - Handler persists entity to database, returns
{"id": <int>} - Bundle stores file ID in hidden form field
- Form Submission — Hidden field values are collected
- Data Transformation —
DropzoneTransformerconverts IDs back to entity objects via Doctrine - Persistence — Form submission handles OneToMany/ManyToOne relationships automatically
File Removal Flow
- User clicks "Remove" link on file preview
- Dropzone.js sends DELETE (or POST) to
removeHandlerroute - Handler deletes entity, returns
{"id": <int>} - Widget removes preview from DOM
- On next form submission, removed ID is not included, relationship is updated
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():
Upgrading from v1
If you're upgrading from the original emr-dev/symfony-dropzone:
- Bundle namespace changed —
Ethsam\SymfonyDropzone(wasEmrDev\SymfonyDropzoneBundle) - Form type import — Update:
use Ethsam\SymfonyDropzone\Form\DropzoneType; - Option names — No changes; all options are backward compatible
- PHP requirement — Now requires PHP ≥8.1
- Symfony support — Now supports Symfony 5.4, 6.x, 7.x
- Data transformer — Automatic; no manual entity conversion needed
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:
- Fork the repository
- Create a feature branch:
git checkout -b feat/your-feature - Commit your changes:
git commit -m "feat: add your feature" - Push to the branch:
git push origin feat/your-feature - 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
- Samuel Etheve — Current maintainer
- Emomaliev M. — Original author (emr-dev/symfony-dropzone)
- Dropzone.js — File upload library
All versions of symfony-dropzone with dependencies
symfony/dependency-injection 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/config 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
doctrine/orm Version ^2.12 || ^3.0