I want to create universal multiple file uploader, but I don't know what approach should I choose to develop it.
I have Attachment model and attachments table in the database. Also I have model Item and table items. These two a connected via item_attachment table (maybe it will be morph connection in the future, so many models can have attachments).
I thought about several approaches (examples are for create form for item):
Use some js uploader (like Dropzone) and develop separate controller
to handle uploads (AttachmentsController). So when I upload files,
controller will return json response with id's to js, and then they
will be inserted to the form as hidden elements. After submitting
form, they will be attached to the item.
Don't use js, and process uploads directly in ItemsController.
Don't use js, develop a Service, where uploads will be handled and
call it's methods in ItemsController.
What can you recommend? Maybe you have your approach?
Thanks
Related
I am building a survey questionnaire in PHP using Laravel and there are five HTML pages (one for each section). Do I need to create separate controllers for each HTML page in order to process the data to the database?
Usually it is good to stick to the different logic-different controller.
As you provided very small amount of info, its not clear what you want to do, but based on the info I understand, you’ll just need one controller and one method for all the html pages.
I have two entities: Image and Post, that are linked by a ManytoOne relationship. The entity Image is used to handle file upload and store upload relative data (like absolute path...). I am using Symfony2 Cookbook tutorial dealing with file uploads.
I am now building a form that allows a user to:
Enter some post specific informations (like title, content..)
upload with jQuery/AJAX many images for the post.
Send the the whole form by button click.
I am still not finding the right approach to implement this solution regarding data persistence in the database.The problem for me is:
In the entity Image, an attribute ($post_id) is used as Foreign Key and will store the post id. The user will upload many images before the entity post is persisted. All the instances of Image created each time will not contain a value for post_id. In my opinion, performance will be affected if I:
update all the rows in image table after persisting an instance of Post.
Create an empty Post instance first, use its id in the Image instances, then update Post instance.
Any suggestions are highly appreciated.
Why don't you use this way of working with your forms?
http://symfony.com/doc/current/cookbook/form/form_collections.html
And in this way you only upload the images with the entire form.
If you need to preview the photos as the user selects them in the file inputs than you can check this answer
How to preview image before uploading in jquery
But it will not work on older browsers like IE8, IE9.
Has anyone faced this feature request and were able to resolve it? We have a webapps that is capable of creating a form as a template. That template will basically be called and user will need to fill out the form before it got push into the db. So the form is created directly inside the application and the fields, labels and variables are all defined when the form is created by user using the apps. Since the form is always going to be changing, I can't hardcode the activity in android and have to create it manually and recompile every time a new form is created. Is there a way for us to read the label, variables setting that's stored in db either in XML format or called as JSON and build the form dynamically everytime the form is called via android? Am I making any sense? Please advise?
Yes. Everything you do in XML (view creation, positioning etc) can be done dynamically via code as well.
A simple way would to be to put a single ScrollView with a single LinearLayout inside it. Then in your activities onCreate(), you can read your JSON or XML file just like any other file (you can store this is assets folder or maybe query it from your backend). Then depending on your variables you can initialize and add TextViews and EditText's to the LinearLayout. The ScrollView will expand infinitely to accommodate all your form elements.
Just make sure you don't do any long-running operation such as querying from your backend or reading from your file in the main UI thread. Another caveat is that if ScrollView does not recycle views and putting too many views in it (say more than 20) can make your application run out of memory and slow down/crash.
You can create a form in relative layout having all the fields/view you require in XML, then on Runtime in code According to your label name in db or whatever you are using, you can hide/show the fields/view which are needed dynamically. This way you can preserve the position and setting of each field as when 1 view is hidden other views are going to take its position.
I, have successfully implemented uploadify script into my app, files are being uploaded to /web/uploads folder.
I have entity Order witch can have multiple attachments OneToMany-unidirectional relation to File entity, uploadify is a part of Order form.
Now, I would like to transform ulpoaded files into File entity presisted to DB, and set it as related to Order that was created with form.
I suppose I have to add some kind of form ID to Order entity and persist it to DB, so uploadify can send this ID and I'll know witch files are related to witch form instance (Maybe use of CSRF token?)
In general, I have no clear idea of how to implement this feature, my english isn't very good, hope everyone will understand my intentions, I'll be thankful of any help or hints on implementation.
I have done this like that:
Each Order entity on construct gives an unique ID base64_encode(microtime()) witch is persisted into DB, then on files form I get this ID from DB and pass it with uploadify postData, them I have clear link witch file was uploaded to witch Order
is it possible to create inner( nested ) forms in php
in our application i want to upload user details to mysql server including user recent work ( that is image ). image is stored in my uploads folder and the path of that image is stored in my database.
that's way i am using inner form to upload image to uploads folder and returns uploaded image path. when the mail form submitted then user details and image path will stored in mysql database this is my idea is it possible or not please give me suggestions...
It is not possible to create nested forms in HTML, the server side language is irrelevant.
You can have multiple submit buttons and use the value of the successful one (i.e. the one that was used to submit the form) to decide if you should accept an image upload and return to the form (repopulated it with the submitted data) or process the other submitted data.
FORMS are part of HTML and not part of PHP at all. And HTML doesn't allow you to have nested FORMS. The best bet, if you want to upload the image and preview before you submit the actual user data would be to use some JS and an IFRAME to simulate nested forms.
An example of what I explained is here : http://www.openjs.com/articles/ajax/ajax_file_upload/
NOTE This is NOT an Ajax file upload (noted in the article too). But this will help you do what you are looking for