Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 184.108.40.206 release ready!
Owner and Founder. Opencart
Here we will learn how to make a controller to upload a file and download the file in Symfony. Its quiet easy as in Symfony its quiet similar to how you do it in core PHP. So lets start! We are creating a controller which will upload a file and save its entry in a database table let the Entity that correspond to the Database Table is ‘UploadedFile’. Our entity ‘ UploadedFile’ will have 4 columns:
So lets start with our controller thats DefaultController, we have to create an action lets take uploadAction() so the controller will look like
Now we have to create a parameter named ‘file_directory’ in config.yml file to declare the path where the file is to be stored. So go to app/config/config.yml and add the below mentioned line under ‘parameters:‘ tag
Now its done when you will upload a file now the file will be stored in the path with a different name and you can see the entry in database. Now send your file as a form data and you can see this working.
Its time for the next step, as now we have file in our system so we are creating an action to download that file. You can take any way to distinguish between files but here I am using FileId so our link (route) will have FileId in it as
And you are ready to go! Access the link and you will have your file downloaded with the name it was uploaded not with the name it was saved on your server. For more info go to Symfony Components.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.