Upload image file dont save the file, but I see the post data OK

Hello all, I have the next form:




$form = ActiveForm::begin(['id' => 'form-profile-edit', 'options' => ['enctype' => 'multipart/form-data']]); ?>

     <?= Html::activeFileInput($model, 'image_upload', ['class' => 'hidden', 'id' => 'file-avatar', 'accept' => 'image/*', 'onchange' => 'javascript:this.form.submit()'])?>

<?php ActiveForm::end();



This rules in the model:




['image-upload', 'file', 'extensions' => ['png', 'jpg', 'jpeg'], 'maxSize' => 45000],

[['image-upload'], 'safe'],



And this code in the controller:




if ($model->load(Yii::$app->request->post())) {


            $file = \yii\web\UploadedFile::getInstance($model, 'image_upload');

            if ($file) {

                //print_r($_FILES);

                echo "<br>pathactual: " . getcwd();

                echo "<br>basename: " . $file->baseName;

                echo "<br>extension: " . $file->extension;

                echo "<br>name: " . $file->name;

                echo "<br>SaveUrl: " . Yii::$app->homeUrl . "assets/avatars/" . $file->baseName . "." . $file->extension;

                echo "<br>Error: " . $file->error; //This shows 0

                echo "Size: " . $file->size;


                $model->avatar = $file->baseName. "-big." . $file->extension;


                if($model->update(true, ["avatar"])){

                    echo "<br>avatar actualizado";

                    Yii::$app->getSession()->setFlash('profile-Msg-OK', Yii::t("app", "Generic_Changes_OK"));

                    //Guardamos el fichero del avatar

                    if($file->saveAs(Yii::$app->homeUrl . "assets/avatars/" . $file->baseName . "-big." . $file->extension)){

                        echo "<br>Imagen guardada correctamente.";

                    }else{

                        echo "<br>Imagen no guardada correctamente: " . $file->error; //This shows 1


                    }


}



I can see the $file object correct, size, tempName, baseName, extension… I save the avatar name in $model->avatar and then I make the update. This works fine.

Now, I execute the saveAs method but always enters in else, the $file->errror value in this moment is 1. I see the UploadedFile documentation and see:

I Search the possible status here: http://www.php.net/manual/en/features.file-upload.errors.php and I see that 1 corresponds to:

Then, I go to my php.ini file (I revised it from phpinfo) I have 40M

The files what I am using to test have 14 and 16 KB.

Any idea about this?

Try to increase your maxSize to 450000 just to ensure problem is not in that line.