FileUpload::save PHP Method

save() public method

主函数,验证并保存图片
public save ( )
    public function save()
    {
        //检查类型
        if (!$this->checkType()) {
            return false;
        }
        //检查大小
        if (!$this->checkSize()) {
            return false;
        }
        //生成新文件的路径
        $file = $this->getFileName();
        //保存
        if ($this->instance->saveAs($file)) {
            $this->filename = $file;
            return $file;
        } else {
            $this->addError('upload', '文件上传失败');
            return false;
        }
    }

Usage Example

Esempio n. 1
0
 public function actionUpdate($id)
 {
     $model = $this->loadBiz(trim($id));
     $model->setScenario('sell');
     $this->performAjaxValidation($model);
     if (!empty($_POST)) {
         $model->attributes = $_POST['ARBiz'];
         //            dump($_FILES);
         //            控制器中使用实例如下:
         $upload = new FileUpload(array($model, 'license_photo'), 'upload/groupon');
         //model处理文件上传  $upload = new FileUpload(array($model,'pic'),'upload/goods');
         if (!$upload->isNull()) {
             if ($filename = $upload->save()) {
                 $model->license_photo = $filename;
                 //                      dump($filename);
             } else {
                 print_r($upload->getErrors());
                 throw new CHttpException('300', '文件上传失败');
             }
         }
         //            dump($model->attributes);
         if ($model->save()) {
             //                $return_url = $_POST['return_url'];
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
All Usage Examples Of FileUpload::save