验证.csv文件时出现Laravel MIME问题 [英] Laravel MIME issue while validating .csv file

查看:286
本文介绍了验证.csv文件时出现Laravel MIME问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几篇有关在使用laravel上传文件时检查文件扩展名的问题的帖子.

I have read couple of post regarding the issue of checking the file extension while upload a file using laravel.

我遇到了同样的问题,即使花了一个小时来解决这个愚蠢的事情,也没有提出解决方案.

I have the same issue and didn't file the solution even if spending an hour behinding the silly thing.

这是我的验证规则.

public function rules()
{
    return [
       'sheet' => 'required',
       'file' => 'mimes:csv',
    ];
} 

但是需要工作文件,但要使用哑剧.

However required is working file but on mimes.

我尝试了其他几种方式,例如:

I tried couple of other ways i founded like:

return [
    'sheet' => ['required', 'mimes:csv']
]

 

return [
    'sheet' => ['required', 'mimes:text/csv']
]

 

return [
    'sheet' => 'required|mimes:text/csv'
];

 

return [
    'sheet' => 'required|mimes:csv'
];

 

return [
    'sheet'          => 'required',
    'extension'      => 'required|in:csv'
];

上面一行都没有工作,有时表明无效文件通过了验证.

Above none of line is working sometime says not valid file sometime passes through the validation.

我怀疑文件无效,然后从Microsoft网站下载了新的示例文件.那根本不是问题.

I doubted for invalid file, then I downloaded fresh sample file from Microsoft site. That not the issue at all.

有人可以帮助我吗?

谢谢!

推荐答案

惊讶!

它正在为CSV提供text/plain哑剧,这就是问题的原因.

Its getting text/plain mime for the CSV, that was the cause of the issue.

因此,要解决此问题,我刚刚找到了负责text/plain的扩展名,并且找到了 txt ,所以我刚刚更新了规则:

So to fix this I just found which extension is responsible for text/plain and I found txt so i just updated my rules:

return [
    'sheet' => 'required|mimes:csv,txt'
];

这篇关于验证.csv文件时出现Laravel MIME问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆