我有这部分代码:
if ($this->request->isPost() && $this->request->hasFiles()) {
$post = $this->request->getPost();
$file = $this->request->getUploadedFiles();
if ($form->isValid($post)) {
$form->bind((array) $this->request->getPost(), $entity);
$entity->save();
// Do some other stuff
}
}
有没有办法将 $file
传递给 Phalcon\Forms\Form 对象?
或者检查包含文件和文本的表单是否有效的另一种做法?
最佳答案
要验证文件,您必须使用 FileValidator 类作为此示例:
$file = new FileValidator([
'maxSize' => '10M',
'messageSize' => _('Your file is huge. Max allowed is 10 Mb'),
'allowedTypes' => ["image/jpeg", "image/png"],
'messageType' => _('File type is not permitted. Try with JPG, GIF, etc..'),
'messageEmpty' => _('Cannot be empty. Please upload a file')
]);
$this->validator->add('filesInputName', $file);
$messages = $this->validator->validate($_FILES);
关于php - 如何将 $_FILES 绑定(bind)到 Phalcon 表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37334666/