Uploading Multiple Image In Yii

I have been trying to upload multiple file i.e. image.

my model Student.php looks like




class Student extends CActiveRecord {


//    public $photo;


    function tableName(){

        return 'student';

    }


    function rules(){

        return array(

            array('name,address,roll,photo,image ','required'),

            array('photo', 'file'),

            array('image'),

        );

    }

}



my Controller looks like




public function actionSaveStudent(){

       // $model=new Student;


        $model=new Student();  // this is my model related to table

//   

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

            'model'=>$model,

        ));


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

        {

            $model->name=$_POST['name'];

            $model->address=$_POST['address'];

            $model->roll=$_POST['roll'];

            $rnd = rand(0,9999);  // generate random number between 0-9999

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




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

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

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

            $model->photo = Yii::app()->basePath.'/student/'.$fileName;

            $model->image = Yii::app()->basePath.'/created_htdocs/'.$fileName;

            $uploadedFile->saveAs(Yii::app()->basePath.'/../student/'.$fileName);





            $uploadedFile->saveAs(Yii::app()->basePath.'/../created_htdocs/'.$fileName);




            // $model->photo = $fileName;







                if($model->validate())

            {

                if($model->save())

                {

                    echo "saved";

                }

                else

                    echo 'failure';

            }

            else

                print_r($model->getErrors());


        }

       // $this->render("newstudent");

    }

}

?>



and my view looks like




<form action="savestudent"  enctype="multipart/form-data" method="post">


   <label> Name: <input name="name" type="text" ></label> <br><br>

   <label> Roll: <input name="roll" type="text" ></label><br><br>

   <label>Address: <input name="address" type="text" ></label><br><br>

    <label>Upload_photo:</label>

        <?php echo CHtml::activeFileField($model,'photo'); ?><br><br>Attachment 5384 not found.

    <?php echo CHtml::activeFileField($model,'image'); ?><br><br>

    <input type="submit" name="submit" id="submit" value="Save">


</form>



and i got error Property "Student.image" is not defined.

This line is causing that error:




<?php echo CHtml::activeFileField($model,'image'); ?>



This still won’t work while the $photo attribute of Student is commented out though.

I’ve deleted your duplicate thread. If you wish to include the files you attached again, you should update your first post here to add them.