需要帮助来验证我的表单输入 我需要用户只能上传扩展名为.log
的文件到目前为止,我已尝试使用下面显示的代码但验证程序仍然拒绝输入,即使文件是.log
提前致谢
$validator = Validator::make($request->all(),
[
'email' => 'required|email',
'file_log' => 'mimes:text/plain,log'
],
[
'email.email' => 'Please input valid email address',
'file_log.mimes' => 'Mohon hanya mengunggah file yang berekstensi .log ',
]
);
答案 0 :(得分:0)
请检查:
'file_log' => 'mimes:text/x-log '
另一种方式
$validator = Validator::make(
[
'file' => $request->file,
'extension' => strtolower($request->file>getClientOriginalExtension()),
],
[
'file' => 'required',
'extension' =>'required|in:log',
]
);
答案 1 :(得分:0)
好吧我终于找到了答案 谢谢你的回答
// Create custom validation rule
Validator::extend('logfile', function ($attribute, $value, $parameters, $validator) {
$regexPattern = '/\.log$/';
$filename = $value->getClientOriginalName();
return preg_match($regexPattern, $filename);
});
$validator = Validator::make($request->all(),
[
'email' => 'required|email',
'file_log' => 'logfile',
],
[
'email.email' => 'Please input valid email address',
'file_log.logfile' => 'Please upload only file .log',
]
);