0

I have check extension of uploaded file in php if jpg|png|gif than upload otherwise not allow to upload

$allowed =  array('gif','png' ,'jpg');
$filename = $_FILES['video_file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
    echo 'error';
}

but what happen when i change .php or .mp3 file to jpg|png|gif and upload

so how i can stop this type of file upload in php

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39

1 Answers1

2

With this you can get the mimetype and can check against your "whitelist":

 $finfo = finfo_open(FILEINFO_MIME_TYPE);
 echo finfo_file($finfo, $filename);
BlackNetworkBit
  • 768
  • 11
  • 21