Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Display Images From Protected Folder In Dataprovider Set

$
0
0
I had a look at this post but I havent quite figured how to achieve this yet.

To try and explain as best I can what I'm trying to achieve i'll explain (forgive the probable ramblings)

So I have a $dataProvider, it lists a load of items using CListView. I have some stored some item pictures in a protected website with temporary names.

In mt $dataProvider I have these tmp_names so what I have tried to do unsuccesfully is in the _view
CHtml::link('<img src="' . Yii::app()->request->baseUrl .'/controller/method/tmp_name" />', array('product/index', 'id'=>$data['id'], 'slug'=> $data['slug']));


Within the controller

	public function getProtectedImage($id)		
	{
						
		$image = Company::model()->find('tmp_name=:id', array('id' => $id)); 
		
		$dest = Yii::getPathOfAlias('application.uploads');
		
		$file = $dest .'/' . $image->tmp_name . '.' . $image->extension;
								
		if(file_exists($file)){

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



That I had hoped would render the appropriate image for each record in the CListView, but it doesn't, what am I doing wrong?

thanks in advance

Jonny

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>