UploadFile.php 867 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /** @author Julio Montoya */
  4. /**
  5. * Class HTML_QuickForm_Rule_UploadFile.
  6. */
  7. class HTML_QuickForm_Rule_UploadFile extends HTML_QuickForm_Rule
  8. {
  9. /**
  10. * Checks if the given element contains an uploaded file of the filename regex.
  11. *
  12. * @param array Uploaded file info (from $_FILES)
  13. * @param string Regular expression
  14. *
  15. * @return bool true if name matches regex, false otherwise
  16. */
  17. public function validate($elementValue, $regex)
  18. {
  19. if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
  20. (!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
  21. return is_uploaded_file($elementValue['tmp_name']);
  22. } else {
  23. return false;
  24. }
  25. }
  26. // end func _ruleCheckFileName
  27. }