1
votes

I have some php code checking the type of files that users upload:

  $fileType = $_FILES['file']['type'];
  $allowedFileTypes = array('image/jpeg','image/gif','image/png','image/jpg');
  if(!in_array($fileType, $allowedFileTypes)) {echo 'fileTypeNotAllowed'; exit;}

I find gif & png files upload without triggering the echo but jpg files trigger the echo.

below is an example of a file that triggers the echo:

enter image description here

Any advise on what I'm doing wrong here?

thx

1
echo $fileType when uploading the jpeg see what it saysKyle Hudson
Maybe your code won't allow beach photosTchoupi
What does $fileType contains? echo 'fileTypeNotAllowed: '.$fileType;Green Black
Try using !in_array(strtolower($fileType, $allowedFileTypes)). in_array is case sensitive.Baylor Rae'
yes it was the beach... lol... got it working strtolower fixed it and I've also added the extra file types... used the echo fileType to see the problem. thankyou so much...Adam

1 Answers

1
votes

Well, you want to check what they are uploading... So I would use !in_array(strtlower($fileType, $allowedFileTypes)) in_array.

That should clear everything up.