Yii2 Uploaded file question

Hello everyone.

Is there a way to create a folder and upload file in it.

I mean lets say i wanna upload a PDF file, my upload path is /uploads/.

Before the file gets uploaded i wanna create a folder like 9 dicember 2015 and upload the file inside it.

so the upload path would be /uploads/9 dicember 2015/uploadedfile

Can someone help?



Read the guide for uploaded file


Here is the method that save the uploaded file


It use php move_uploaded_file() which DOES NOT create the directory tree

To create the directory tree you should use

\yii\helpers\FileHelper::createDirectory ( $path, $mode = 509, $recursive = true );

with recursive set to true (is the default) it will create the full path



By the way I suggest you to use all number for the date without space or by using _ or - as separator.

Using ISO 8601 would be the best for readability YYYY-MM-DD