Regex to validate mime type

Asked

Viewed 183 times

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 upload an image system only, in the case of this mime types:

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

if(!preg_match($pattern, $verifyimg['mime']){
        die("Só imagens!");
    }

1 answer

0

You can do it this way, it gets 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!");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.