php Laravel 5 - 验证 Mime 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30405960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:45:49  来源:igfitidea点击:

Laravel 5 - Validating Mime types

phplaravel-5

提问by BrunoMartinsPro

I have an uploader that works fine without rules, but when i create a rule i get the error:

我有一个上传器可以在没有规则的情况下正常工作,但是当我创建规则时出现错误:

LogicException in MimeTypeGuesser.php line 127:
Unable to guess the mime type as no guessers are available 
(Did you enable the php_fileinfo extension?)

My article request rules

我的文章请求规则

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [

        'Image' => 'required|mimes:jpeg'

    ];
}

My form

我的表格

{!! Form::open(['url' => 'blog', 'files'=> true]) !!}
    <div class="form-group">
    {!! Form::label('Image', 'Upload:') !!}
    {!! Form::file('Image', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
    {!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>  
{!! Form::close() !!}

回答by Sulthan Allaudeen

You should enable the following line in your php.ini and then restart your apache

您应该在 php.ini 中启用以下行,然后重新启动 apache

extension=php_fileinfo.dll

Enabling mean just uncomment the line in your php.ini file

启用意味着只需取消注释 php.ini 文件中的行

i.e., From this ;extension=php_fileinfo.dllto extension=php_fileinfo.dll

即,从这个;extension=php_fileinfo.dllextension=php_fileinfo.dll

回答by user11950276

If your php.ini file don't have extension=php_fileinfo.dll. Don't worry, let add this line in it. Good luck!

如果您的 php.ini 文件没有extension=php_fileinfo.dll。别担心,让我们在其中添加这一行。祝你好运!