tested few hours now, the krajee file input plugin seem not workable on my multiple image upload.
view file
<?= $form->field($productGallery, 'image[]')->widget(FileInput::classname(), [
'options'=>[
'accept'=>'image/*',
'multiple'=>true
],
'pluginOptions'=>[
'allowedFileExtensions'=>['jpg','gif','jpeg', 'png'],
'showUpload' => false,
]
]) ?>
controller
public function actionCreate()
{
$model = new Product();
$productGallery = new ProductGallery;
if ($model->load(Yii::$app->request->post())) {
$file = UploadedFile::getInstance($productGallery,'image');
var_dump($file);
exit;
} else {
return $this->render('create', [
'model' => $model,
'productGallery' => $productGallery,
]);
}
}
model
class ProductGallery extends \yii\db\ActiveRecord
{
public $image=array();
/**
* @inheritdoc
*/
public static function tableName()
{
return 'product_gallery';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['product_id'], 'required'],
[['product_id', 'visible'], 'integer'],
[['created_at' ,'image'], 'safe'],
[['name', 'img'], 'string', 'max' => 255]
];
}
}
however if i am not doing multiple upload by replacing view file to
<?= $form->field($productGallery, 'image')->widget(FileInput::classname(), [
'options'=>[
'accept'=>'image/*',
'multiple'=>true
],
'pluginOptions'=>[
'allowedFileExtensions'=>['jpg','gif','jpeg', 'png'],
'showUpload' => false,
]
]) ?>
it works, what shall i do in this case to handle multiple upload?