9three Posted October 29, 2009 Share Posted October 29, 2009 Hey, I'm creating an uploader and for some reason when I add to check other mime type files it doesnt recognize it properly. if ($_FILES['file']['type'] != 'image/jpeg' || $_FILES['file']['type'] != 'image/png' || $_FILES['file']['type'] != 'image/gif') { echo ' <script type="text/javascript"> parent.document.getElementById("uploadTxt").innerHTML = "That file extension is not allowed: '.$_FILES['file']['type'].' Please try again." </script>'; return false; } This doesn't work. But if I remove || $_FILES['file']['type'] != 'image/png' || $_FILES['file']['type'] != 'image/gif' And just leave != 'image/jpeg' it works correctly. It's confusing me? Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 see whats going in and confirm its not your fault echo $_FILES['file']['type']; if ($_FILES['file']['type'] != 'image/jpeg' || $_FILES['file']['type'] != 'image/png' || $_FILES['file']['type'] != 'image/gif') { echo ' <script type="text/javascript"> parent.document.getElementById("uploadTxt").innerHTML = "That file extension is not allowed: '.$_FILES['file']['type'].' Please try again." </script>'; return false; } Quote Link to comment Share on other sites More sharing options...
9three Posted October 29, 2009 Author Share Posted October 29, 2009 I'm already echoing it.. parent.document.getElementById("uploadTxt").innerHTML = "That file extension is not allowed: '.$_FILES['file']['type'].' Please try again." I've tried 2 files: a jpg and a jpeg jpg works jpeg does not Output: That file extension is not allowed: image/jpeg Please try again. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 i think a whoile back i had this problem, and i think i rember it being that they have different mime types Quote Link to comment Share on other sites More sharing options...
9three Posted October 29, 2009 Author Share Posted October 29, 2009 I tried png and gif and it doesn't work either. The mime type has to be jpeg for it to work correctly. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 trust me just print_r($_FILES['file']); before you do any checking so you can see what php see's Quote Link to comment Share on other sites More sharing options...
jcombs_31 Posted October 29, 2009 Share Posted October 29, 2009 make sure you aren't exceeding any file size directives in php.ini, if the file is larger than what is allowed it is probably getting kicked out before it can analyze the mime-type. Quote Link to comment Share on other sites More sharing options...
9three Posted October 29, 2009 Author Share Posted October 29, 2009 the jpeg I'm uploading is 1.21mb and it uploads correctly. The png I just tried is 63kb. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 29, 2009 Share Posted October 29, 2009 Think about the logic of if ($_FILES['file']['type'] != 'image/jpeg' || $_FILES['file']['type'] != 'image/png' || $_FILES['file']['type'] != 'image/gif') { Upload a gif file... first test ($_FILES['file']['type'] != 'image/jpeg') gives true. No further checking is done because you're using the || operator. Therefore, the whole "if" is true and the file is rejected. Try using && instead of || Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 29, 2009 Share Posted October 29, 2009 You should in fact be putting the accepted strings in to an array and then use the in_array function to test if the received value is in the array of accepted values. Quote Link to comment Share on other sites More sharing options...
9three Posted October 29, 2009 Author Share Posted October 29, 2009 argh very true. my logic was off. thanks. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 Think about the logic of if ($_FILES['file']['type'] != 'image/jpeg' || $_FILES['file']['type'] != 'image/png' || $_FILES['file']['type'] != 'image/gif') { Upload a gif file... first test ($_FILES['file']['type'] != 'image/jpeg') gives true. No further checking is done because you're using the || operator. Therefore, the whole "if" is true and the file is rejected. Try using && instead of || those ones are hard to spot, i think you may have it there, well spotted Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.