Yii2错误中未安装fileinfo PHP扩展

Yii2错误中未安装fileinfo PHP扩展,yii2,Yii2,我的Web应用程序中附加了文件上载功能,但存在问题。代码在我的本地主机上运行得很好,但在我已经上传的真实服务器上运行得不好。我把目录权限改为可写 if ($model->load(Yii::$app->request->post())) { $session = Yii::$app->session; $user_id = $session->get('role'); //get the instance

我的Web应用程序中附加了文件上载功能,但存在问题。代码在我的本地主机上运行得很好,但在我已经上传的真实服务器上运行得不好。我把目录权限改为可写

if ($model->load(Yii::$app->request->post())) 
    {   
       $session = Yii::$app->session;
       $user_id = $session->get('role');

        //get the instance of the uploaded file
        $imageName = $model->Fname."_".$model->Lname;

        $model->file = UploadedFile::getInstance($model, 'file');

        if($model->file)
        {    
          //SHA512 base password encription
          $model->password = crypt($model->repeatpassword,'$6$rounds=1212$16charactersalt');

          //save image pathe to db
          $model->image = 'uploads/profile_image/'.$imageName.'.'.$model->file->extension;
          $model->role = $user_id;
          $model->save();
          $model->file->saveAs( 'uploads/profile_image/'.$imageName.'.'.$model->file->extension );  
        }          
        //return $this->redirect(['index']);
        return $this->goHome();
    } 


我认为您的Yi2代码中没有任何问题。 这可能是PHP配置的问题

文件信息从PHP 5.3.0开始默认启用扩展名

Windows用户必须在php.ini中包含捆绑的php_fileinfo.dll文件才能启用此扩展

请访问以下链接了解更多详细信息


您只需在php.ini中取消注释这一行:

extension=php_fileinfo.dll

在model.model where中添加
“checkExtensionByMimeType”=>false,
?你是说我的数据库模型类?你使用的是windows操作系统吗?不,这是一个linux服务器。你可以访问php.ini文件吗?我的代码在我的本地服务器(XAMPP)中工作得很好。我把我的文件上传到real server,然后这个错误被发现了。我已经告诉过你,你的代码中没有任何问题。这是PHP配置(PHP.ini)的问题。谢谢你,Mohammad!