Name File Upload

hi all of master yii…i have a problem about download files.i have this code :




public function actionCreate()

        {

                $model=new Naskah;

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

                {

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

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

                        

                        if($model->save())

                                $model->lampiran->saveAs(Yii::app()->basePath . '/../files/' .'.jpg');

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

                }


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

                        'model'=>$model,

                        //'model'=>$this->loadModel($id_naskah),

                ));

        }



file success saved in ‘files’ directory but the file is no name.how to get the name of that file? Any help would be greatly appreciated

The ‘lampiran’ attribute should hold the file’s name, because when the CUploadedFile object is cast to a string it returns the filename.

In controller action




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

$file_name=$model->lampiran;

 

if($model->save())

$file_name->saveAs(dirname(Yii::app()->basePath) . '/../files/'.$fileName);        

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



thanks…that’s a great solution.success :lol: