图片上传preg_match检查文件[重复]

This question already has an answer here:

I'm trying to fix a picture upload. But I have some troubles with the check if the file is a picture. Before I used eregi_replace but that function is deprecated and now I'm wondering is there possible to use preg_match and check in an array for a match or how should I do this?

    $name = "Picture.jpg";
    $picture = array("/^JPG/", "/^PNG/", "/^GIF/", "/^gif/", "/^png/", "/^jpg/", "/^JPEG/", "/^jpeg/");
    $something = preg_match($picture, $name, $matches, PREG_OFFSET_CAPTURE, 3); 
    print_r($something);

Like that or something? I dont have a clue, hope you can help me!

</div>

Like below:

$name = "Picture.jpg";

if (preg_match('/\.(jpe?g|png|gif)$/i', $name, $matches)) {
  //...
}

But note this only check the filename, if you want to check it's a real image, you should validate the actual mime-type.