upload photo problem

Hi, my objective is, to upload a photo for a resume. wherein the path/filename of the photo should be saved at the table where the corresponding resume that matches it, resides.

what or how am I gonna do this? ,

  1. I created a folder outside the protected folder and named it cvphotos.

  2. am trying to follow $this tutorial, but my brain can’t grasp how it works.

here’s what I have




        public function actionUpload()

        {

            $cvid = Yii::app()->request->getQuery('id');

            

            $model = new Wsrecruitreferences;

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

            {

                $model->ImagePath = $_POST['Wsrecruitreferences'];

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

                if($model->save())

                {

                    $model->image->saveAs(Yii::app()->basePath. '/../cvphotos/'.$model->image);

                }

            }

            $this->render('upload',array('model'=>$model));



I know, that code above is all wrong , can someone tell me or show me a solution for this? …the image path should be saved at a table with corresponding resume id ???

hey!

if you want the attribute image to be filled with the path of the image, i’d suggest that you create a “virtual” public attribute in your model called imageFile to upload and try something like this (not tested, just an idea)




public function actionUpload()

        {

            $cvid = Yii::app()->request->getParam('id',null);  //what is it for?

            

            $model = new Wsrecruitreferences;


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

            {

                $model->attributes = $_POST['Wsrecruitreferences'];  //this line was incorrect


                $file = CUploadedFile::getInstance($model,'imageFile');


                $model->image = dirname(Yii::app()->basePath) . DIRECTORY_SEPARATOR . 'cvphotos' . DIRECTORY_SEPARATOR . $file->name;


                if($model->save())

                {

                    $file->saveAs($model->image);

                }

            }

            $this->render('upload',array('model'=>$model));

}



for testing purposes, make sure your cvphotos has a 777 permission setting on Linux to avoid problems when saving the file

hope this helps

:)

regards!

Hello,

if you look here :http://www.yiiframework.com/forum/index.php?/topic/18636-ajouter-image/ on the last post, I wrote a working example to upload an image the way you requested.

The text is in french, but the code is quite simple.

Cheers

Benn