Make sure the uploaded file is an image in PHP

Is there a good way to make sure the downloaded file is an image in PHP?

+3
source share
4 answers

Use Fileinfo .

+2
source

Pass the resulting file to the getimagesize () function . If the file is an image (of a supported type), you will get an array with the image type, which is stored as the third element of the array. If the file is not the result of the image, there will be false.

+1
source

, , MIME, FileInfo .., - - GD ImageMagik .

0

:

if(strpos($_FILES["fieldname"]["type"], "image") !== FALSE) {
    // is an image
} else {
    // is no image
}
-2

Source: https://habr.com/ru/post/1732301/


All Articles