将 filemimetype 验证器添加到 Zf2 表单时 HTTP 响应返回状态 0

HTTP response returning status 0 when adding filemimetype validator to Zf2 form

当我以我的一种形式将 filemimetype 验证器添加到我的验证器链时出现错误。我的 http 状态为 0,Apache 2 日志中没有消息。有人知道发生了什么吗?这是代码:

$fileInput->getValidatorChain()
->attachByName('filesize', ['max' => 1440000], false)
// when i uncomment the following line and send the form the described error occurs
//->attachByName('filemimetype', ['mimeType' => 'image/jpeg,image/png,image/x-png,image/jpg,image/gif'], true)
;

此外,根据我的 php_info() 输出启用了 FileInfo 扩展,这意味着它应该被 filemimetype 验证器使用(参见 mime type validator zf2 manual) .

我们在 OS X 上上传文件和 MIME 类型检查时遇到了类似的问题。 将以下选项设置为 mime 类型验证器:

->attachByName(
    'filemimetype',
    [
        // this is optional and not necessary, falls back to HTTP informations of uploaded file if mime type cannot be resolved
        // 'enableHeaderCheck' => true,
        'magicFile' => false,
        'mimeType' => [
            'image/jpg',
            'image/jpeg',
            'image/png',
        ]
    ]
);

https://github.com/zendframework/zf2/issues/6493 and http://framework.zend.com/manual/current/en/modules/zend.validator.file.mime-type.html

干杯