I Can Upload Image But Can't Display It

hi all

I’m trying to display an image i upload it, but I can not so what’s wrong

controller




function actionUpload()

        {

            $dir = Yii::getPathOfAlias('application.uploads');


            $uploaded = false;


            $model=new Upload();


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

            {

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


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


                if($model->validate())

                {

                    $name=date('ymdHis').'.'.$file->getExtensionName();

                    

                    $uploaded = $file->saveAs($dir.'/'.$name);

                    

                    $ProductFilemodel=new ProductFile;

                    

                    $ProductFilemodel->product_id=$this->_product->id;

                    

                    $ProductFilemodel->name=$name;

                    

                    if($ProductFilemodel->save())

                        $this->redirect(array('product/view', 'id'=>$this->_product->id));

                }

            }


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

                'model' => $model,

                'uploaded' => $uploaded,

                'dir' => $dir,

            ));

        }



controller




public function actionView($id)

	{

            $dir = Yii::app()->getBaseUrl(false);

            

            $productFileDataProvider=new CActiveDataProvider('ProductFile',

                array(

                    'criteria'=>array(

                    'condition'=>'product_id=:productId',

                    'params'=>array(':productId'=>$this->loadModel($id)->id),

                    ),

                    'pagination'=>array(

                        'pageSize'=>10,

                    ),

                )

            );

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

			'model'=>$this->loadModel($id),

                        'productFileDataProvider'=>$productFileDataProvider,

                        'dir'=>$dir,

		));

	}



view




<?php echo CHtml::image($dir.'uploads/'.$data->name); ?>



can anyone help me

thank you

You’re trying to access a file that’s in your protected directory. If you want your images to be accessible via a web browser you need to upload them to a folder in your web root, such as:


Yii::getPathOfAlias('webroot.uploads');

thank you

it is working now

It was my fault