How we can save a image in a folder yii2 framework? -


when uploading image saved in default folder /web. want save images in user defined folder.

if user defined folder, chances pretty have create directory on fly, uploadedfile method not do. yii2 use createdirectory() method in "yii\helpers\basefilehelper" class. ex:

use yii\web\uploadedfile; use yii\helpers\basefilehelper;  $model->uploaded_file = uploadedfile::getinstance($model, 'uploaded_file');  $unique_name = uniqid('file_'); $model->file_type = $model->uploaded_file->extension; $model->file_name = $unique_name.'.'.$model->file_type; $model->file_path = 'uploads/projects/'. $project_id;  basefilehelper::createdirectory($model->file_path);  $model->uploaded_file->saveas($model->file_path .'/'. $model->file_name); $model->save(); 

check out createdirectory


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -