小编KFO*_*KFO的帖子

ZF2 文件上传:文件为空

我在 Zend Framework 2 应用程序中上传图像时遇到问题,我想我的代码中某处存在配置错误。

这是我目前的代码。我像 ZfcUser 表单一样创建了表单和过滤器。

表单扩展提供事件表单(ZfcBase)

$file = new Element\File('image');
$file->setLabelAttributes(array('class' => 'control-label col-sm-4'));
$file->setLabel('image');
$this->add($file);
Run Code Online (Sandbox Code Playgroud)

过滤器扩展提供事件输入过滤器(ZfcBase)

$this->add(
    array(
        'type' => 'Zend\InputFilter\FileInput',
        'name' => 'image',
        'required' => true,
        'validators' => array(
            array(
                'name' => 'File\UploadFile',
            ),
        ),
        'filters' => array(
            array(
                'name' => 'File\RenameUpload',
                'options' => array(
                    'target' => './public/img/uploads',
                    'randomize' => true,
                ),
            ),
        ),
    )
);
Run Code Online (Sandbox Code Playgroud)

在验证过程中,方法 FileInput::isValid() 被调用 - 但值始终为空,我不知道为什么会这样。

HTML-Form设置为multipart/form-data,Server配置也没有问题。我用于测试的文件只有 80KB。

任何人的想法,有什么问题?

php validation file-upload zend-framework2

1
推荐指数
1
解决办法
1874
查看次数

标签 统计

file-upload ×1

php ×1

validation ×1

zend-framework2 ×1