Api of Multiple File Uploading in Yii2

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

After getting lot's of error and don't know how to perform multiple images api in yii2 finally I get it today

This is my question I asked on forum and it works for me https://forum.yiiframework.com/t/multiple-file-uploading-api-in-yii2/130519

Implement this code in model for Multiple File Uploading `php [['media'], 'file', 'maxFiles' => 10], ` you can add extension or any skiponempty method also

And this is my controller action where I prformed multiple file uploading `php public function actionMultiple(){

    $model = new Media;
    $model->post_id = '2';
    if (Yii::$app->request->ispost) {
        $model->media = UploadedFile::getInstances($model, 'media');
        if ($model->media) {
            foreach ($model->media as $value) {
                $model = new Media;
                $model->post_id = '2';
                $BasePath = Yii::$app->basePath.'/../images/post_images';
                $filename = time().'-'.$value->baseName.'.'.$value->extension;
                $model->media = $filename;
                if ($model->save()) {
                    $value->saveAs($BasePath.$filename);
                }
            }
            return array('status' => true, 'message' => 'Image Saved'); 
        }
    }
    return array('status' => true, 'data' => $model);
}
If any query or question I will repond