I have the below which works perfectly for uploading a single image. when i try to upload multiple it only uploads the first image. can anyone point me in the right direction?
view:
echo $form->field($model, 'image[]')->widget(FileInput::classname(), [
'options'=>['accept'=>'image/*', 'multiple'=>true],
]);
Controller:
public function actionCreate()
{
$model = new PhotoPhotos();
$imagine = Image::getImagine();
if ($model->load(Yii::$app->request->post())) {
// process uploaded image file instance
$images = $model->uploadImage();
if ($model->save()) {
// upload only if valid uploaded file instance found
if ($images !== false) {
$path = $model->getImageFile();
$paththumb = $model->getImageFileThumb();
$images->saveAs($path);
Image::thumbnail($path, 100, 100)->save(Yii::getAlias($paththumb), ['quality' => 80]);
}
return $this->redirect(['../article', 'id' => $model->article_id]);
} else {
Model:
public function uploadImage() {
// get the uploaded file instance. for multiple file uploads
// the following data will return an array (you may need to use
// getInstances method)
$image = UploadedFile::getInstances($this, 'image');
foreach ($image as $images) {
// if no image was uploaded abort the upload
if (empty($images)) {
return false;
}
// store the source file name
$this->image_src_filename = $images->name;
$extvar = (explode(".", $images->name));
$ext = end($extvar);
// generate a unique file name
$this->image_web_filename = Yii::$app->security->generateRandomString().".{$ext}";
// the uploaded image instance
return $images;
Thank you in advanced!