Yii file field checking

guys. i want to ask how to check the filefield is null or not?

if ($_POST['emp']['image'] !== '' || $_POST['emp']['image'] !== null) {

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

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

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

}else {

   $model->image = null;

   $model->imageurl = null;


Hi PK95,

[font="Arial"]CUploadedFile::getInstance[color="#222222"][size="2"]([/size][/color]CModel[color="#222222"][size="2"] $model, string $attribute), returns null [/size][/color][color="#222222"][size="2"]if no file is uploaded for the specified model attribute.[/size][/color][/font]

[font="Arial"] [/font]

[font="Arial"][color="#222222"][size="2"]So, you can check it like this:[/size][/color][/font]

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

$model->imageUrl    = null;

if($model->image != null){

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



Hi xuxana,

Thanks for helping me. its really solve my problem.

Thanks a lot! ^_^