Upload Image And Save It In My Images Folder

Hi All,

Good Morning,

i have one question regarding my student module.

i am uploading my student photo when i am creating student profile. and save that photo in my images folder.

file upload code is works properly…but not save in my folder…

here is my code…

kindly suggest proper solution.

When i am inserting data after that it gives me an error like:

Call to a member function saveAs() on a non-object in /var/www/demo/protected/controllers/StudentController.php

here is my action: student_photo is my field of student table.

    public function actionCreate()


{


	 $model=new Student;


	 $this->performAjaxValidation($model);


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


	{


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


		$model->dob = date("Y-m-d", strtotime($model->dob));


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


		


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


		$ext = pathinfo($image, PATHINFO_EXTENSION);


		$rnd = rand(0,9999);


		$fileName = "{$rnd}-".$ext;


		$model->student_photo=$fileName;*/


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


			$image->saveAs('/images/'.$fileName);		


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


        	         } 


    	  }


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


		'model'=>$model,


	));


}

Thanks in Advance,

With Regards,

Janvi

Remove the line:


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

and try again. Also you got the */ in


$model->student_photo=$fileName;*/

Hello BizleySir,

Thanks Sir,

its working…path is not proper set…now its working…

Thank u again.

Regards,

Janvi