【发布时间】:2017-06-14 02:29:06
【问题描述】:
我正在尝试通过上传表单上传 PHP 脚本,但 Laravel 5 验证器拒绝它。
这是一个例子:
$input_name = 'myfile';
$requirements = 'mimes:text/x-php|required|max:10000';
$file = array($input_name => Input::file($input_name));
$rules = array($input_name => $requirements);
$validator = Validator::make($file, $rules);
if ($validator->fails()) { // The fail occurs here
echo Input::file($input_name)->getMimeType(); // the output is text/x-php
}
调试数据:
我还尝试将 mime 类型定义为
x-php和php。在终端
file --mime-type test.php返回text/x-phpLaravel
getMimeType()函数也返回 text/x-phptest.php 文件足够小,所以不是大小限制。
如果定义为
mimes:jpeg,jpg,png,gif|required|max:10000,则相同的代码适用于图像
有谁知道在验证器中应该如何定义任何类型的脚本文件?
提前感谢您的帮助。
【问题讨论】: