Question

how is this work

if($_FILES['SelectedFile']['type'] != 'image/png' or 'image/jpg' or 'image/gif' || 'image/jpeg'){
    outputJSON('Unsupported filetype uploaded.');
}

my file is something.PNG and it doesn't pass above if statement. I change the code to 'image/PNG' because it might be the uppercase issue but it was not the case. I wonder why.

edit

var_dump($_FILES['SelectedFile']['type'])

array(5) { ["name"]=> string(11) "Capture.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(24) "C:\xampp\tmp\phpE58A.tmp" ["error"]=> int(0) ["size"]=> int(7818) } 

No correct solution

OTHER TIPS

Your expression is incorrect, it should be:

$type = $_FILES['SelectedFile']['type'];
if ($type != 'image/png' && $type != 'image/jpg' && $type != 'image/gif' && $type != 'image/jpeg') {
    outputJSON('Unsupported filetype/uploaded');
}

Or doesn't distribute in programming languages like it does in natural languages.

Try this:

$haystack = array("image/png","image/jpg","image/jpeg","image/gif");
if(!in_array(strtolower($_FILES['SelectedFile']['type']), $haystack){
    outputJSON('Unsupported filetype uploaded.');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top