在yii Framework中上载文件时出错

时间:2014-06-06 05:59:52

标签: yii

  public function actionCreate()
    {
        $model=new Add;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['yt0']))
        {
            //$rnd = rand(0,9999);  // generate random number between 0-9999
            $model->attributes=$_POST['Add'];
            $uploadedFile=CUploadedFile::getInstance($model,'add_videolink');
            //$fileName = "{$rnd}-{$upenter code hereloadedFile}";  // random number + file name
            $model->add_videolink = $uploadedFile;
            // var_dump($model->save());exit();
            if($model->save())
            {
                if(!empty($uploadedFile))
                {
                    $uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads'.$fileName);

                }
                $this->redirect(array('admin'));
            }
        }

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

当我尝试运行此代码时,它会显示" move_uploaded_file():" copy()函数的第二个参数不能是目录'

3 个答案:

答案 0 :(得分:2)

我认为上传后你会错过“/”。之后如果你还有问题,那么 尝试上传小尺寸文件。

答案 1 :(得分:0)

尝试在上传后添加“/”:

来自:

$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads'.$fileName);

为:

$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads/'.$fileName);

答案 2 :(得分:0)

你在saveAs()

上错过了一个斜杠符号
$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads/'.$fileName);