如何解决没有文件上传错误Zend Framework 3验证
我想使用Callback
验证,但continue_if_empty
对File
不起作用,它返回No file was uploaded
错误。但是所有适用于Input
和Select
的东西。我需要帮助。
$this->add([
'name' => 'images','required' => false,'allow_empty' => true,'continue_if_empty' => true,'type' => FileInput::class,'filters' => [
[
'name' => Rename::class,'options' => [
'target' => '/var/www/project/public/website/content/tmp/image_' . md5(time()),'randomize' => true,],'validators' => [
[
'name' => Callback::class,'options' => [
'callback' => [$this,'imageValidator'],]);
public function imageValidator($value,$context)
{
dd($context);
}
解决方法
这帮助我解决了“未上传文件”错误。
在打开表单标签之前,将此行包括在视图模板(.phtml)中:
$ form-> prepare()
完整示例:
<!-- File: upload-form.phtml -->
<?php
$form->prepare(); // The correct enctype is set here
$fileElement = $form->get('image-file');
echo $this->form()->openTag($form);
?>
<div class="form-element">
<?= $this->formLabel($fileElement) ?>
<?= $this->formFile($fileElement) ?>
<?= $this->formElementErrors($fileElement) ?>
</div>
<button>Submit</button>
<?= $this->form()->closeTag() ?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。