Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 3375

[Wiki] Uploading Default Image

$
0
0

This Article is about the Uploding a default Image.

Purpose: If the User haven't image to upload, this default image will be replaced in the DB.

On your Controller:

Create();

$_POST['ModelName']['image'] = $model->image;
 
              $uploadedFile=CUploadedFile::getInstance($model,'image');
 
             if(!empty($uploadedFile))
             {
             $model->image=$uploadedFile;
             }
             else
             {
             $model->image= "default.jpg";
             }
 
if($model->save())
 
{
 
            if(!empty($uploadedFile))  // check if uploaded file is set or not
                {
                    $uploadedFile->saveAs(Yii::app()->basePath."/../image/".$model->image);
                }
 
/*.......*/
}

Note: Place the Default.jpg Image in the image Folder.


Viewing all articles
Browse latest Browse all 3375

Trending Articles