Hi guys,
I have an images folder outside protected folder and I want to create a dropdownlist listing the filenames from that folder to the view
Here’s what I did,
public function actionCreate()
{
$model=new Blog;
$files = new FilesystemIterator(Yii::app()->baseUrl . '/images/');
$images = new RegexIterator($files, '/\.(?:jpg|png|gif)$/i');
foreach($images as $image) {
$filename = $image->getName();
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Blog']))
{
$model->attributes=$_POST['Blog'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
'filename' => $filename,
));
}
However when I run it, It says No such file or directory. I’m not sure how to get the files in the images folder.
I believe its not a good practice to use those classes in yii (FilesystemIterator). Can you guys give me a better approach rather than this. I would really appreciate it. Thank you.