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

时间:2015-04-27 15:35:57

标签: php validation zend-framework zend-framework2 mime-types

我在我的一个表单中将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)。

1 个答案:

答案 0 :(得分:1)

我们在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/6493http://framework.zend.com/manual/current/en/modules/zend.validator.file.mime-type.html

欢呼声