shanghaixcn 2012-05-11 21:15:19 3238次浏览 3条回复 0 0 0

无法上传文件。 控制器代码:

public function actionCreate()
{
    $model=new Picture;
    if(isset($_POST['Picture']))
    {	
        $model->attributes=$_POST['Picture'];
        $model->image=CUploadedFile::getInstance($model,'image');
        if($model->save())
        {
            $model->image->saveAs(Yii::app()->basePath.'/images/picname.png');
        }
        $this->redirect(array('admin'));
    }

    $this->render('create',array(
        'model'=>$model,
    ));
}

视图代码:

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'picture-form',
	'enableAjaxValidation'=>false,
)); ?>

<div class="row">
    <?php echo CHtml::activeFileField($model, 'image'); ?>
</div>

<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>
您需要登录后才可以回复。登录 | 立即注册