Ejemplo n.º 1
0
 /**
  * ฟังก์ชั่น ตรวจสอบไฟล์อัปโหลดว่าเป็นรูปภาพหรือไม่
  *
  * @param array $typies ชนิดของไฟล์รูปภาพ ได้แก่ jpg gif png
  * @param array $files ตัวแปรที่ได้จาก $_FILES
  * @return array|boolean คืนค่าแอเรย์ [width, height, mime] ของรูปภาพ หรือ  false ถ้าไม่ใช่รูปภาพ
  */
 public static function isValidImage($typies, $files)
 {
     // ext
     $imageinfo = explode('.', $files['name']);
     $imageinfo = array('ext' => strtolower(end($imageinfo)));
     if (!in_array($imageinfo['ext'], $typies)) {
         return false;
     } else {
         // Exif
         $info = getImageSize($files['tmp_name']);
         if ($info[0] == 0 || $info[1] == 0 || !gcms::checkMIMEType($typies, $info['mime'])) {
             return false;
         } else {
             $imageinfo['width'] = $info[0];
             $imageinfo['height'] = $info[1];
             $imageinfo['mime'] = $info['mime'];
             return $imageinfo;
         }
     }
 }