php - Symfony2 Add multiples images to an entity. The clean way -


my question more architecture question real problem.

model

at moment have 1 entity , collection of images (image entity) attached them (@manytomany).

view

actually have stable code running on production it's nightmare maintain. i'm using js , ajax. js listening fake multiple input , sending images symfony. @ point symfony2 creating fake temporarily folder , adding inside images (huge piece of code).

i don't think can't run without ajax , js (remember can't change input file value) , using layout box if user want drag ad drop images instead of adding manually.

controller

after real form submitted, controller checking files inside temporarily folder , adding images collection of entity (i don't think right approach) , moving images temp folder s3 box.

question

any idea manage problem in different way? avoiding storing images in temp folder or/and using symfony2 forms , doctrine listeners / postupdate-postpersist.

i've been through problem before , there no way around it: if want upload images asynchronously (ajax), @ point gonna have store them in sort of temporal folder. creates well-known problem when user uploads doesn't complete rest of form , leaves page. need sort of mechanism remove "orphaned" images, not belong completed request , sitting there in temp folder.

there bundle have been using extensively, allows this. provides easy way of handling file uploads using whatever ajax solution need (or making own), , provides nice file system abstraction (which can use store images in s3 bucket). coolest feature orphanage, let clean temp uploaded not used images running command. matter of doing cron command clean folder regularly.

this bundle: https://github.com/1up-lab/oneupuploaderbundle

you can integrate symfony, take account gonna have 2 actions, 1 upload images asynchronously (which can form or not), , 1 process real form. putting both of them trivial, make sure keep track of temporal uploaded images, using sessions, filesystem folder, or table in database.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -