hvt-multipleimage-upload

For multiple image upload in yii we have to work in two files which are the following

  • The controller file
  • The view file

For controller file

public function actionCreate()
{
//loading the model
$model=new MultiFileUpload;
if(isset($_POST['MultiFileUpload']))
{
$model->attributes=$_POST['MultiFileUpload'];
$images=array();
$images = CUploadedFile::getInstancesByName('images');
if(!file_exists(Yii::app()->basePath .'/images/username'))
{
mkdir(Yii::app()->basePath .'/images/username' ,777);
}
$i="1";
foreach ($images as $image => $pic) 
{
$ext = pathinfo($pic->name);
$models[$i] =new MultiFileData;
$filename=$ext['filename'].date('Y_m_d_H_i_s').".".$ext['extension'];
$models[$i]->file=$filename;
if ($pic->saveAs(Yii::app()->basePath .'/images/'.$username. 8 .'/'.$filename)) 
{
$models[$i]->save();	
}
}	$i++;
}
}	

For the view file

Your view file must be like this


Add multi upload element in view file and it will be like this