No image inside root/protected/images

hi guys,

i have follow the instruction upload file using a model but the image didn’t save inside the protected/images folder even i already success save to database. i need to create the images folder by myself or it will automatic create the images folder after save. All helps is needed.


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

        {


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

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


            if($model->save())

            {

                $model->uploadedFile->saveAs(Yii::app()->basePath . '/../images/' . $model->uploadedFile);


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

            }

            // }

        }

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

    }



thanks,

If you check CUploadedFile::saveAs function, you will find out that it use php move_uploaded_file function, which doesn’t create destination directory, so you have to create it manually.

hi Ivica,

thank for reply. Problem solved. But facing another problem. i put the display image code at create view or what? i now can save the image to directory but i can’t see the display image view or result. Pls help.


<?php echo CHtml::image(Yii::app()->baseUrl . '/images/' . $data->image, 

$data->description,

   array("class" => "clickme", "title" => $data->title, "width"=>"300", "height"=>"220")); ?>

thanks again.

By default the protected folder denies all requests for web files through the use of a .htaccess. IMO you shouldn’t be uploading files into the protected folder anyway so I suggest moving where you’re saving them to.

Hi Say_Ten,

success move to other directory outside protected file… Thank for suggestion.

Thank again.