How can I retrieve file in _protected/frontend/uploads

I am using the /kartik-v/yii2-widget-fileinput along with the yii2 improved advanced template and the images are being saved to the following directory


In my model I have the following which sets the paths

Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/uploads/';

Yii::$app->params['uploadUrl'] = Yii::$app->urlManager->baseUrl . '/uploads/';

Which displays the following between the src attribute


however the image is saved within


I am not sure if this is a permissions thing or if I should change/move the uploads directory so would appreciate some guidance.

You can’t directly access files in your protected folder in the browser. Here is a Yii 1 function to do it. You can convert it to yii2, it’s the same concept.

CHtml::link('<img src="' . $this->createUrl('/images/image', array('data'=>$data['data'])) . '" />', array('product/index', 'id'=>$data['product_id'], 'slug'=> $data['product_slug']));

public function actionImage($data)        { 

 $image = Images::model()->find('tmp_name=:data', array('id' => $data)); 

  $dest = Yii::getPathOfAlias('application.uploads');  $file = $dest .'/' . $image->tmp_name . '.' . $image->extension;  if(file_exists($file)){ ob_clean();

 header('Content-Type:' . $image->logo_type); readfile($file); exit; 

}  }

Or you can tell yii to publish the file into assets then call it using asset manager. The above came from stack but I’ve used something very similar and it works.

I had this problem and just created symlinks from frontend/web/images &backend/web/images to common/images. I couldn’t see how to do it using assets