parent
0c71327813
commit
dfdc842b8f
@ -0,0 +1,26 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** @author Julio Montoya */ |
||||
|
||||
/** |
||||
* Class HTML_QuickForm_Rule_FileName |
||||
*/ |
||||
class HTML_QuickForm_Rule_FileName extends HTML_QuickForm_Rule |
||||
{ |
||||
|
||||
/** |
||||
* @param $value array Uploaded file info (from $_FILES) |
||||
* @param null $options |
||||
* @return bool |
||||
*/ |
||||
public function validate($value, $options = null) |
||||
{ |
||||
if ((isset($elementValue['error']) && $elementValue['error'] == 0) || |
||||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) { |
||||
return is_uploaded_file($elementValue['tmp_name']); |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** @author Julio Montoya */ |
||||
|
||||
/** |
||||
* Class HTML_QuickForm_Rule_MaxFileSize |
||||
*/ |
||||
class HTML_QuickForm_Rule_MaxFileSize extends HTML_QuickForm_Rule |
||||
{ |
||||
/** |
||||
* @param $value array Uploaded file info (from $_FILES) |
||||
* @param null $options |
||||
* @return bool |
||||
*/ |
||||
public function validate($elementValue, $maxSize) |
||||
{ |
||||
if (!empty($elementValue['error']) && |
||||
(UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error']) |
||||
) { |
||||
return false; |
||||
} |
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { |
||||
return true; |
||||
} |
||||
|
||||
return ($maxSize >= @filesize($elementValue['tmp_name'])); |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** @author Julio Montoya */ |
||||
|
||||
/** |
||||
* Class HTML_QuickForm_Rule_MimeType |
||||
*/ |
||||
class HTML_QuickForm_Rule_MimeType extends HTML_QuickForm_Rule |
||||
{ |
||||
/** |
||||
* Checks if the given element contains an uploaded file of the right mime type |
||||
* |
||||
* @param array Uploaded file info (from $_FILES) |
||||
* @param mixed Mime Type (can be an array of allowed types) |
||||
* @access private |
||||
* @return bool true if mimetype is correct, false otherwise |
||||
*/ |
||||
public function validate($elementValue, $mimeType) |
||||
{ |
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { |
||||
return true; |
||||
} |
||||
if (is_array($mimeType)) { |
||||
return in_array($elementValue['type'], $mimeType); |
||||
} |
||||
return $elementValue['type'] == $mimeType; |
||||
} // end func _ruleCheckMimeType |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** @author Julio Montoya */ |
||||
|
||||
/** |
||||
* Class HTML_QuickForm_Rule_UploadFile |
||||
*/ |
||||
class HTML_QuickForm_Rule_UploadFile extends HTML_QuickForm_Rule |
||||
{ |
||||
/** |
||||
* Checks if the given element contains an uploaded file of the filename regex |
||||
* |
||||
* @param array Uploaded file info (from $_FILES) |
||||
* @param string Regular expression |
||||
* @access private |
||||
* @return bool true if name matches regex, false otherwise |
||||
*/ |
||||
public function validate($elementValue, $regex) |
||||
{ |
||||
if ((isset($elementValue['error']) && $elementValue['error'] == 0) || |
||||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) { |
||||
return is_uploaded_file($elementValue['tmp_name']); |
||||
} else { |
||||
return false; |
||||
} |
||||
} // end func _ruleCheckFileName |
||||
} |
||||
Loading…
Reference in new issue