shanghaixcn 2012-05-11 15:02:51 2555次浏览 3条回复 0 0 0

yii上传文件是用CUploadedFile吗?怎么使用?

  • 回复于 2012-05-11 15:15 举报

    看一下这个教程!
    http://www.yiichina.com/tutorial/11

  • 回复于 2012-05-11 15:34 举报

    感谢舰长。thanks

  • 回复于 2012-05-11 18:10 举报

    文件上传不了。

    class PictureController extends Controller
    {
        public function actionCreate()
        {
            $model=new Picture;
    
            // Uncomment the following line if AJAX validation is needed
            // $this->performAjaxValidation($model);
            if(isset($_POST['Picture']))
            {
                $model->attributes=$_POST['Picture'];
                $model->d=CUploadedFile::getInstance($model,'d');
                if($model->save())
                {
                    $model->d->saveAs('images/123.png');
                }
                $this->redirect(array('admin'));
            }
    
            $this->render('create',array(
                'model'=>$model,
            ));
        }
    }
    

    视图文件:

    <div class="row">
        <?php echo $form->labelEx($model,'d'); ?>
        <?php echo CHtml::activeFileField($model, 'd'); ?>
        <?php echo $form->error($model,'d'); ?>	
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>
    
您需要登录后才可以回复。登录 | 立即注册