MaxFileSize.php 780 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /** @author Julio Montoya */
  4. /**
  5. * Class HTML_QuickForm_Rule_MaxFileSize.
  6. */
  7. class HTML_QuickForm_Rule_MaxFileSize extends HTML_QuickForm_Rule
  8. {
  9. /**
  10. * @param $value array Uploaded file info (from $_FILES)
  11. * @param null $options
  12. *
  13. * @return bool
  14. */
  15. public function validate($elementValue, $maxSize)
  16. {
  17. if (!empty($elementValue['error']) &&
  18. (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])
  19. ) {
  20. return false;
  21. }
  22. if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
  23. return true;
  24. }
  25. return $maxSize >= @filesize($elementValue['tmp_name']);
  26. }
  27. }