我使用 Symfony 1.4 和 Propel 作为 ORM。我使用 Symfony 表单创建了一个表单,其中包含一些文本输入和文件上传元素。形式结构,
$this->setWidgets(array(
'name' =>new sfWidgetFormInput(),
'mobile' =>new sfWidgetFormInput(),
'resume' =>new sfWidgetFormInputFile()
));
$mime_array=array("application/pdf","application/msword");
$this->setValidators(array(
'name' =>new sfValidatorString(array('required' => true)),
'mobile' =>new sfValidatorAnd(array(new sfValidatorNumber(),new sfValidatorString(array('required' => true, 'min_length' => 10, 'max_length' => 10)))),
'resume' =>new sfValidatorFile(array('mime_types' => $mime_array))
));
但是文件上传验证不适用于 Ms Word 文件,但适用于 PDF 文件(因为用户可以上传 PDF 或 Ms Word 文档)。