如何在Yii中上传文件。 在控制器中,我无法获取除文件名之外的文件详细信息

It's showing an error like "Undefined variable: fullImgSource".

Can anyone help me with this?

in view

<div class="form">
<?php
  $form=$this->beginWidget('CActiveForm', array(
      'id'=>'Candidate-form',
      'enableClientValidation'=>true,
      'clientOptions'=>array(
      'validateOnSubmit'=>true
    ),
    'htmlOptions' => array('enctype' => 'multipart/form-data')
  )); 
?>
<p class="note">Fields with <span class="required">*</span> are required.       </p>
<?php echo $form->errorSummary($model); ?>
<?php
  echo $form->labelEx($model, 'delete_YN');
  echo $form->fileField($model, 'delete_YN');
  echo $form->error($model, 'delete_YN');
?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Add' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->

In Controller code is here

Uploadfile

$model = new Candidate;
if(isset($_POST['Candidate']))
{
  $model->attributes=$_POST['Candidate']; 
  $name=@$_FILES["Candidate"]["name"]["delete_YN"];
  $model->delete_YN  = CUploadedFile::getInstance($model,'delete_YN');
  if($model->save())
    $fullImgSource = Yii::getPathOfAlias('webroot').'/upload/'.$name;
  $model->delete_YN->saveAs($fullImgSource);
  $model->delete_YN = $name;
  $model->save();
  $this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array('model'=>$model,));

Yii have built in support for file uploads. You don't need to worry about $_FILES.

Kindly go through with, How to upload files using model

Regards

Your $model is most likely not passing validation (check $model->getErrors() if validation fails for more information on what exactly failed), so the save() method does not go through and $fullImgSource ends up not being defined. You should wrap your code in braces after the save method since the following code relies on it to succeed.

$cUploadedFile = CUploadedFile::getInstance($model, 'delete_YN');
if ($cUploadedFile) {
    $model->delete_YN  = $cUploadedFile;
}
if ($model->save()) {
    if ($cUploadedFile) {
        // Save file from temp to a specific location
        $cUploadedFile->saveAs('upload/' . $model->delete_YN);
    }
    $this->redirect(array('view','id'=>$model->id));
}

Hopefully this answers why you are getting that error. Now as to how to actually handle uploads, you do not have to access $_FILES to get your upload. CUploadedFile::getInstance($model, 'attribute_name') should take care of that for you.