Symfony2 Upload Form & User ID - php

So I'm trying to create a form in the User Bundle for Symfony where I want to allow users to upload photos and eventually use them as a profile picture.
Using this for example: http://symfony.com/doc/master/cookbook/doctrine/file_uploads.html
I want to figure out how to assign the user ID to the photo while uploading the image as just an "ID".png itself.
Would anyone know? This would take using Doctrine of course.

Related

Send identifiers between views and controller method with Laravel

Working on an application in laravel that has the capability to create article and add photos. With photos you can add a main one to the article or just add photos to a repository.
Once an article is saved to the database it redirects to a view that will allow you to associate a photo with the recently saved article.
I'm wanting to send an some kind of identifier from the create article view to the photo controller method so it will know what to respond with. Then from the photo controller method send that same identifier to the add photo view so when the photo is submitted to the database the controller knows it's a primary article photo.
I'm trying to avoid having to write several different methods that contain a lot of the same code. I would rather the photo controller be able to tell that the photo is a primary article photo and it knows what to do with it.
Any help would be greatly appreciated.
I recommend you to have hidden form field in the view that contains the identifier and photo controller will store it in the session that any other controller can read later.

WordPress - passing form values to a download manager

CONTEXT
We are creating a Wordpress site that allows users to log-in, select a resource, fill out a form, and then download a PDF that is stamped with the information filled out on the form. We are currently using the Wordpress Content Manager plugin on a Genesis child theme to manage downloads. This plugin has the functionality to control access to files, make a download button conditional on filling out a form and stamp a PDF with static information about the user. The workflow should look like this:
User selects resource from a list
User is taken to a form and fills it out
On form submission, user is taken to a download page where a download link for this resource's PDF is available
The PDF is downloaded, stamped with information that the user filled out on the form in the previous step.
PROBLEM
We would like to pass information from the form to the PDF stamper. However, there is not native functionality that allows this. The plugin is limited to stamping information that is in the user's profile. We are wondering what the simplest way of passing data from a form back to the plugin might be.

ManyToOne relationship where the child entity serves for AJAX file uploading

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.

How to implement multi-upload ques with Symfony2 and uploadify?

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

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

Categories