MaxFileSize.php 773 B

12345678910111213141516171819202122232425262728
  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. * @return bool
  13. */
  14. public function validate($elementValue, $maxSize)
  15. {
  16. if (!empty($elementValue['error']) &&
  17. (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])
  18. ) {
  19. return false;
  20. }
  21. if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
  22. return true;
  23. }
  24. return ($maxSize >= @filesize($elementValue['tmp_name']));
  25. }
  26. }