【发布时间】:2014-03-25 14:42:04
【问题描述】:
我在 Zend Framework 2 应用程序中上传图像时遇到问题,我认为我的代码中某处存在配置错误。
这是我当前的代码。我像 ZfcUser 表单一样创建了表单和过滤器。
表单扩展 ProvidesEventsForm(ZfcBase)
$file = new Element\File('image');
$file->setLabelAttributes(array('class' => 'control-label col-sm-4'));
$file->setLabel('image');
$this->add($file);
过滤器扩展 ProvidesEventsInputFilter(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,
),
),
),
)
);
在验证过程中调用 FileInput::isValid() 方法 - 但值始终为空,我不知道为什么会这样。
HTML-Form设置为multipart/form-data,Server配置也没有问题。 我用来测试的文件只有80KB。
任何人的想法,有什么问题?
【问题讨论】:
标签: php validation file-upload zend-framework2