1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace Kotchasan;
12:
13: 14: 15: 16: 17: 18: 19:
20: class Validator extends \Kotchasan\KBase
21: {
22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
34: public static function email($email)
35: {
36: if (function_exists('idn_to_ascii') && preg_match('/(.*)@(.*)/', $email, $match)) {
37:
38: $email = $match[1].'@'.idn_to_ascii($match[2], 0, INTL_IDNA_VARIANT_UTS46);
39: }
40: if (preg_match('/^[a-zA-Z0-9\._\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $email)) {
41: return true;
42: } else {
43: return false;
44: }
45: }
46:
47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public static function isImage($excepts, $file_upload)
57: {
58:
59: $imageinfo = explode('.', $file_upload['name']);
60: $imageinfo = array('ext' => strtolower(end($imageinfo)));
61: if (in_array($imageinfo['ext'], $excepts)) {
62:
63: $info = getimagesize($file_upload['tmp_name']);
64: if ($info[0] == 0 || $info[1] == 0 || !Mime::check($excepts, $info['mime'])) {
65: return false;
66: } else {
67: $imageinfo['width'] = $info[0];
68: $imageinfo['height'] = $info[1];
69: $imageinfo['mime'] = $info['mime'];
70:
71: return $imageinfo;
72: }
73: } else {
74: return false;
75: }
76: }
77: }
78: