How to upload image in profile using yii framework ?

839 views
Skip to first unread message

Manju Bishnoi

unread,
Jun 17, 2014, 7:46:25 AM6/17/14
to php...@googlegroups.com

I have followed this link : http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/

Browse option is coming and it is taking image from the drives but after submitting it is displaying an error message : "Image cannot Be Blank"

 Following is the ActionCreate() in Controller :

 public function actionCreate()

 {

  $model=new Item;              

  // Uncomment the following line if AJAX validation is needed

  // $this->performAjaxValidation($model);

                  if(isset($_POST['Item']))

  {

  //$rnd = rand(0,9999);

                    $model->attributes=$_POST['Item'];

                  //      $uploadedFile=CUploadedFile::getInstance($model,'image');

            //$fileName = "{$rnd}-{$uploadedFile}";  // random number + file name

            //$model->image = $fileName;

                     

                       $model->image=CUploadedFile::getInstance($model,'image');

//$valid=$model->validate() ;

//if($valid)

             //{

           

             if($model->save()){

              //   $uploadedFile->saveAs(Yii::app()->basePath.'/../banner/'.$fileName);  // image will uplode to rootDirectory/banner/

                //$this->redirect(array('admin'));


             $model->image->saveAs('E:\wamp\www\uptest\images'.$model->image);

             }

                         /*

    if($model->save())

    $this->redirect(array('view','id'=>$model->id));*/

  }


  $this->render('create',array(

   'model'=>$model,

  ));

 }


Please do reply for the post. It will be a great help for me. Thanks in Advance.

Sebastian Krebs

unread,
Jun 17, 2014, 7:56:43 AM6/17/14
to php...@googlegroups.com
Hi,

You should refer http://www.yiiframework.com/community/ on where to find help for Yii.

Regards,
Sebastian


--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/2777fb96-fb8c-486e-af10-f6dc19cb82f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
github.com/KingCrunch

Robert Hafner

unread,
Jun 17, 2014, 8:30:31 AM6/17/14
to php...@googlegroups.com

This isn’t the appropriate place for this. We’re a standards group, not a help group.

I would recommend checking out ##php on Freenode, posting to PHPHelp on Reddit, or bringing this to StackOverflow. There are a lot of resources available to reach out for help, this just isn’t one of them.

Rob



Reply all
Reply to author
Forward
0 new messages