tommy20 Posted November 7, 2009 Share Posted November 7, 2009 I want to check if a files is either jpeg or jpg and stop exit if it is something else. If tried this but it lets files that are not either jpeg or jpg load. What can i do if (!($uploaded_type=="image/jpg") xor !($uploaded_type=="image/jpeg" ) ) { echo "You may only upload jpg picture files.<br>"; $ok=0; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/ Share on other sites More sharing options...
Zane Posted November 7, 2009 Share Posted November 7, 2009 xor means (either or).. not both. just use or. Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953110 Share on other sites More sharing options...
tommy20 Posted November 7, 2009 Author Share Posted November 7, 2009 That didn't work Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953127 Share on other sites More sharing options...
Zane Posted November 7, 2009 Share Posted November 7, 2009 try if (($uploaded_type != "image/jpg") or ($uploaded_type != "image/jpeg")) Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953129 Share on other sites More sharing options...
Daniel0 Posted November 7, 2009 Share Posted November 7, 2009 I want to check if a files is either jpeg or jpg and stop exit if it is something else. If tried this but it lets files that are not either jpeg or jpg load. What can i do if (!($uploaded_type=="image/jpg") xor !($uploaded_type=="image/jpeg" ) ) { echo "You may only upload jpg picture files.<br>"; $ok=0; exit(); } When you're having trouble with propositional logic, it's often a good idea making a truth table If we say that: p: $uploaded_type=="image/jpg" q: $uploaded_type=="image/jpeg" Then the truth table looks like this: [pre]p | q | ~p ⊕ ~q --------------- T | T | F T | F | T F | T | T F | F | F[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953132 Share on other sites More sharing options...
tommy20 Posted November 7, 2009 Author Share Posted November 7, 2009 This still isn't working Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953133 Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2009 Share Posted November 7, 2009 And if you work out a truth table using OR you will find the it won't work either (because negative logic is being used in the tests, you would need to use AND.) Which is why it is usually best to test for allowed values and do something if a value is one of the possible allowed values. Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953136 Share on other sites More sharing options...
tommy20 Posted November 7, 2009 Author Share Posted November 7, 2009 How can i do that Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953137 Share on other sites More sharing options...
Daniel0 Posted November 7, 2009 Share Posted November 7, 2009 Replace or/xor with and... Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953139 Share on other sites More sharing options...
Mchl Posted November 7, 2009 Share Posted November 7, 2009 How about something easy to scale out? $allowedTypes = array( "image/jpeg", "image/jpg", ); if(!in_array($uploaded_type,$allowedTypes) { echo "You may only upload jpg picture files.<br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953140 Share on other sites More sharing options...
tommy20 Posted November 7, 2009 Author Share Posted November 7, 2009 That doesn't do anything Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953141 Share on other sites More sharing options...
Daniel0 Posted November 7, 2009 Share Posted November 7, 2009 It does anything if it's an illegal filetype... Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953142 Share on other sites More sharing options...
Alex Posted November 7, 2009 Share Posted November 7, 2009 That doesn't do anything Probably because of the syntax error, a missing ), try: $allowedTypes = array( "image/jpeg", "image/jpg", ); if(!in_array($uploaded_type,$allowedTypes)) { echo "You may only upload jpg picture files.<br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953144 Share on other sites More sharing options...
Daniel0 Posted November 7, 2009 Share Posted November 7, 2009 Heh... that's what you get from blindly copy/pasting things without trying to understand it first I guess. Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953146 Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2009 Share Posted November 7, 2009 And unless stated otherwise, all code that is posted comes with an implied disclaimer that it is an untested example showing how you can do something, not that it is actual, final, tested code that can be directly used for any particular purpose. * [* - kind of the same disclaimer that MS ships with its' products, that this is not actual, final, tested code that can be used for any particular purpose.] Quote Link to comment https://forums.phpfreaks.com/topic/180655-check-if-false-using-xor/#findComment-953148 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.