Regex to validate the mime type

1

What would be the regex to validate this mime types only

  • image / bmp
  • image / gif
  • image / x-icon
  • image / pjpeg
  • image / jpeg
  • image / png

I want to make a image upload system only , in case of this mime types:

$verifyimg = getimagesize($_FILES['image']['tmp_name']);

if(!preg_match($pattern, $verifyimg['mime']){
        die("Só imagens!");
    }
    
asked by anonymous 10.11.2017 / 17:29

1 answer

0

You can do this, it's simpler and easier to read:

if (strpos($verifyimg['mime'], 'image/') === false) {
    die("Só imagens!");
}

Using regex:

if (!preg_match('/image\//',$verifyimg['mime'])) {
    die("Só imagens!");
}
    
10.11.2017 / 17:35