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? Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/ 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; } Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947083 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. Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947090 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 Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947101 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. Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947105 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 Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947106 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. Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947109 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. Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947111 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 || Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947135 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. Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947140 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. Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947143 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 Link to comment https://forums.phpfreaks.com/topic/179498-not-recognizing-file-type/#findComment-947146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.