Tag Archives: file upload

How to upload a file in Yii2

If you have worked in Yii1.1 then you will know how to upload a file in Yii, to upload the file in Yii2 is almost the same.

In this article we will be using table named contact with few attributes (id, name, pic) and for this we will go step by step:

Step 1:

Setup global parameter for fileUploadUrl in params array of your configuration file, such as:

Step 2:

Create a Controller that will handle file upload:


Step 3:

To render to View for the file upload form:


Step 4:

Now, set your Model as follows:


with setting all these, now you will be able to upload file, save it in upload folder and save the file name in database table filed.

Happy Coding!