Easy Multiple File Upload in Symfony using the CollectionType Field

File uploads have always been tricky, and handling them gracefully and painless is a challenging task. Avoid duplicates, handle removal and replacing without leaving orphan files somewhere in the database or on the server, showing a nice interface to the user, avoiding the ugly standard grey upload button … a lot of things need to be taken into account when working with file uploads. Luckily, Symfony has some great mechanisms which allow easing the task. In this tutorial I will be describing how I handle multiple file uploads using doctrine events and collection type form fields.

This scenario for this tutorial is a simple one : Folder and Document management. A Folder may contain a number of Documents, whereas a Document can only belong, and thus be uploaded, to a singe Folder. At any time during the Folder creation or modification, we need to be able to add or remove Documents from the Folder.

Read More