function validate($data, &$failed = null) { $ret = parent::validate($data); if ($this->has_file) { try { $errors = array(); foreach ($_FILES as $k => $v) { if (isset($v['error']) && $v['error'] == UPLOAD_ERR_NO_FILE) { if ($this->must) { $errors[] = '请选择上传文件!'; break; } continue; } $fileExt = Helper_Upload::fileExt($v['name']); if (!in_array(strtolower($fileExt), Helper_Upload::getTypes())) { $errors[] = '上传文件的类型不符合要求'; } if ($v['size'] > Helper_Upload::getSize()) { $errors[] = '上传文件的大小超过限制'; } } if (empty($errors)) { return $ret; } $this[$this->has_file]->invalidate(implode(', ', $errors)); return false; } catch (Exception $ex) { $this[$this->has_file]->invalidate($ex->getMessage()); return false; } } else { return $ret; } }