【问题标题】:Laravel 5 upload script filesLaravel 5 上传脚本文件
【发布时间】: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-phpphp

  • 在终端file --mime-type test.php返回text/x-php

  • Laravel getMimeType() 函数也返回 text/x-php

  • test.php 文件足够小,所以不是大小限制。

  • 如果定义为mimes:jpeg,jpg,png,gif|required|max:10000,则相同的代码适用于图像

有谁知道在验证器中应该如何定义任何类型的脚本文件?

提前感谢您的帮助。

【问题讨论】:

    标签: php laravel laravel-5


    【解决方案1】:

    结果表明,Validator 可以使用以下定义的 mime 类型和扩展列表:

    /vendor/symfony/http-foundation/File/MimeType/MimeTypeExtensionGuesser.php

    因此,应在此处定义未知的 mime 类型以使其可用。

    这里有一些更有用的信息: Laravel 5 Mime validation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-21
      • 2017-02-12
      • 2017-07-29
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      • 2016-03-14
      相关资源
      最近更新 更多