file upload with model failing

Hi all,

I’m trying to upload a file using a model, but every time I submit the form it just loops back and renders the form again.

I’ve attached my model, controller and form

P.S I’m using Windows

Your form will be always renders again, also after submit, because

you should make a redirect after save() model, so:




                if( $model->save() ){

                    $uploadPath = Yii::app()->baseUrl.'/upload';

                    $model->location->saveAs( "$uploadPath" );


                    // here you should make a redirect

                    $this->redirect(....);

                    

                }//end inner if



Otherwise, after save() next instruction is to render view.

I’ve tried that but the its still not working.

I think $model->save() is not working, but can’t figure out why

It’s possible.

So check if save() is not working:




                if( $model->save() ){

                    $uploadPath = Yii::app()->baseUrl.'/upload';

                    $model->location->saveAs( "$uploadPath" );


                    // here you should make a redirect

                    $this->redirect(....);

                    

                } 

                else

                {

                    var_dump($model->errors);

                    exit;

                }



I’ve tried that but its still looping, I think ‘$model->save()’ is not executing but I can’t figure out why.

Do you think that you don’t arrive in save() method?

No I don’t think it executes

Put var_dump going back in the code, until receive response from script.

could be a validation error


<?php.

   2

   3 if($model->save()) {

   4     $uploadPath = Yii::app()->baseUrl.'/upload';

   5     $model->location->saveAs( "$uploadPath" );

   6

   7     // here you should make a redirect

   8     $this->redirect(....);

   9 }

  10 // dump the model errors and stop the execution of the program

  11 var_dump($model->errors);die;