image path

I want to save my files and images in directory, but I found out that the directory is empty.

the directory is: "data/course_admin_files/course_files"

See the screen shot below:

7319

image_path.PNG

controller




        $coursefile = UploadedFile::getInstance($model, 'coursefile');

        if(!is_null($coursefile))

        {


            foreach ($this->coursefile as $file) {

  

          $model->course_file_name = $coursefile->name;

          $ext = end((explode(".", $coursefile->name)));

          $model->course_file_path = Yii::$app->security->generateRandomString().".{$ext}";


          Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/../web/data/course_admin_files/course_files/';

      

          $path = Yii::$app->params['uploadPath'] . $model->course_file_path;

          $file->saveAs($path);

        }



Please help me out

Hi,

I think your image path is under /data/… not web/data/… If I am not wrong.





$coursefile = UploadedFile::getInstance($model, 'coursefile');

if (!is_null($coursefile))

    {


            foreach ($this->coursefile as $file) {

  

          $model->course_file_name = $coursefile->name;

          $ext = end((explode(".", $coursefile->name)));

          $model->course_file_path = Yii::$app->security->generateRandomString().".{$ext}";


          Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/data/course_admin_files/course_files/'; //I think your file is not under web/ it is root /data/....

      

          $path = Yii::$app->params['uploadPath'] . $model->course_file_path;

          $file->saveAs($path);

        }