0

嗨,我正在使用 CActiveFrom fileField 将文件上传到服务器,但 pdf 文件没有保存剩余的所有扩展名都保存在这里是我的控制器代码来保存文件

控制器

 if(isset($_POST['Uploadinfo']))
        {
            $model->attributes=$_POST['Uploadinfo'];


            $file = CUploadedFile::getInstance($model, 'imageId');


            $model->imageId=CUploadedFile::getInstance($model, 'imageId');


            $valid = $model->validate();


            date_default_timezone_set('Asia/Kolkata');
            $serverTime = date("Y-m-d H:i:s", time());

            if(!empty($file->name) && $valid)
            {

                $modelFileLocation->filename = microtime() . $file->name;
                $modelFileLocation->orgfilename = $file->name;
                $modelFileLocation->type = 1;
                $modelFileLocation->createdOn = $serverTime;
                $modelFileLocation->lastModifiedBy = 'lecturer';

                $valid = $modelFileLocation -> validate();


                $modelFileLocation->deptId = $_POST['Uploadinfo']['departmentId'];
                print_r($file);

                if ($modelFileLocation->save())
                {
                    $file = CUploadedFile::getInstance($model, 'imageId');
                    print_r($modelFileLocation);
                print_r($file);
                die();  

                $model->userId = $_POST['Uploadinfo']['userId'];
                $model->imageId = $modelFileLocation->id;
                $model->departmentId = 1;
                $model->createdOn = $serverTime;
                $model->lastModifiedBy = 'lecturer';

                    if ($model->save())
                    {

                        $modeldocumentinfo->property = $file->type;
                        $modeldocumentinfo->fileName = $modelFileLocation->filename;
                        $modeldocumentinfo->creator = 'lecturer';
                        $modeldocumentinfo->lastUploadedOn = $serverTime;
                        $modeldocumentinfo->uploadId = $model->id;
                        $modeldocumentinfo->viewers = 0;

                        $modeldocumentinfo->save();

                        $file->saveAs('uploads/files/' . $modelFileLocation->filename);
                            print_r($file);
            die();
                        //Yii::app()->user->setFlash('uploadsuccess', "File Uploaded Successfully...");
                        $this->redirect(array('lmaterialitview'));
                    }
                }

在上面的代码中,我在 $modelFileLocation 模型保存之前和之后打印文件实例,然后这个模型保存文件实例正在获取,但是在保存模型之后,文件实例变空

这是实例代码

实例消息

 CUploadedFile Object ( [_name:CUploadedFile:private] => example.pdf [_tempName:CUploadedFile:private] => C:\wamp\tmp\php4BB.tmp [_type:CUploadedFile:private] => application/pdf [_size:CUploadedFile:private] => 205374 [_error:CUploadedFile:private] => 0 [_e:CComponent:private] => [_m:CComponent:private] => )

在第二个 print_r() 中它正在消失,但对于剩余的扩展,它正在出现并保存

4

1 回答 1

0

只需将 $deleteTempFile 参数设置为 false

$file->saveAs('uploads/files/' . $modelFileLocation->filename, false);
于 2013-02-24T22:04:25.470 回答