maxwel Posted June 6, 2013 Share Posted June 6, 2013 ($_FILES["fileToUpload"]["size"] >= 26214400) dont work, i can upload files less than 25 mb still?! is that normal? i upload file that is 800bytes and it works any idea how to make it work? or if there is another solution? Thanks in advance, Maxwel Quote Link to comment Share on other sites More sharing options...
requinix Posted June 6, 2013 Share Posted June 6, 2013 That tiny little bit of code you posted will work, but only if you surround it in some more code that uses it properly. What is the rest of the code? Quote Link to comment Share on other sites More sharing options...
maxwel Posted June 6, 2013 Author Share Posted June 6, 2013 (edited) <?php ini_set('upload_max_filesize', '70M'); ini_set('post_max_size', '70M'); ini_set('max_input_time', 6000); ini_set('max_execution_time', 300000); $f = 'path'; $obj = new COM ( 'scripting.filesystemobject' ); if ( is_object ( $obj ) ) { $ref = $obj->getfolder ( $f ); //echo 'Directory: ' . $f . ' => Size: ' . $ref->size; $obj = null; } else { //echo 'can not create object'; } if ( $ref->size < 32212254720){ if (($_FILES["fileToUpload"]["type"] == "audio/mp3") || ($_FILES["fileToUpload"]["type"] == "audio/wav") || ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"]<= 70000000) ) { things done else { echo error } echo error space if full } Edited June 6, 2013 by maxwel Quote Link to comment Share on other sites More sharing options...
requinix Posted June 6, 2013 Share Posted June 6, 2013 Please use [code] tags when posting code. if (($_FILES["fileToUpload"]["type"] == "audio/mp3") || ($_FILES["fileToUpload"]["type"] == "audio/wav") || ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"] <= 70000000) )Operator precedence. && has higher precedence than ||, meaning a || b && c works like a || (b && c). Rearranging your code, $mp3 = ($_FILES["fileToUpload"]["type"] == "audio/mp3"); $wav = ($_FILES["fileToUpload"]["type"] == "audio/wav"); $mpeg = ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"] <= 70000000); if ($mp3 || $wav || $mpeg) {Use parentheses to change that behavior. if ( (($_FILES["fileToUpload"]["type"] == "audio/mp3") || ($_FILES["fileToUpload"]["type"] == "audio/wav") || ($_FILES["fileToUpload"]["type"] == "audio/mpeg")) && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"] <= 70000000) ) Quote Link to comment Share on other sites More sharing options...
maxwel Posted June 6, 2013 Author Share Posted June 6, 2013 (edited) still dont work and it pass it as if its higher than 25 mb :S, sigh i used that $mp3 = ($_FILES["fileToUpload"]["type"] == "audio/mp3"); $wav = ($_FILES["fileToUpload"]["type"] == "audio/wav"); $mpeg = ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"] <= 70000000); if ($mp3 || $wav || $mpeg) { instead of that part if (($_FILES["fileToUpload"]["type"] == "audio/mp3") || ($_FILES["fileToUpload"]["type"] == "audio/wav") || ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"]<= 70000000) ) { Edited June 6, 2013 by maxwel Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 6, 2013 Share Posted June 6, 2013 (edited) Operator precedence. && has higher precedence than ||, meaning a || b && c works like a || (b && c). Rearranging your code, Not technically true. ANDs and ORs are executed left to right - assuming there are no parenthetical conditions. EDIT: But, in a way, the nature of AND does make that true based upon the end result. But, ANDs aren't processed before ORs Here are all the possible combinations using that example: if(true || true && true) { echo "A"; } if(true || true && false) { echo "B"; } if(true || false && true) { echo "C"; } if(true || false && false) { echo "D"; } if(false || true && true) { echo "E"; } if(false || true && false) { echo "F"; } if(false || false && true) { echo "G"; } if(false || false && false) { echo "H"; } The output will be ABCDE. ABCD are true for the lone fact that "a" is true. Once the parser sees that the first condition is true and there is an OR condition it exits the condition check entirely and doesn't check b & c at all. It's easy to verify this function test($bool) { echo "X"; return $bool; } if(test(true) || test(true) && test(true)) { echo "A<br>"; } //Output: XA //Exits after the first condition check if(test(false) || test(true) && test(true)) { echo "E<br>"; } //Output: XXXE //Has to check all three conditions That is why you can use an isset() check for a POST var to prevent warning messages //This will produce a warning if 'foo' is not set if($_POST['foo'] == 'bar') { echo "bar"; } //This will NOT produce a warning if 'foo' is not set because it //will exist after the first false due to the AND condition if(isset($_POST['foo']) && $_POST['foo'] == 'bar') { echo "bar"; } Edited June 6, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
maxwel Posted June 6, 2013 Author Share Posted June 6, 2013 ok read post more well and got what u said exactly it worked woot woot but now i have a question about something else, can i ask it here in that topic aswell? its like need a suggestion from you Thanks alot maxwell Quote Link to comment Share on other sites More sharing options...
requinix Posted June 6, 2013 Share Posted June 6, 2013 (edited) Not technically true. ANDs and ORs are executed left to right - assuming there are no parenthetical conditions. EDIT: But, in a way, the nature of AND does make that true based upon the end result. But, ANDs aren't processed before ORsNo, what I said is technically true. Read it again: I didn't say they're executed first, I said they have higher precedence. Meanwhile you are also correct about that not affecting the order of evaluation and about short-circuiting. [edit] If && did not have higher precedence than || then your test script would not output "B". echo (true || true && false) ? "Y" : "N"; // normal echo ( (true || true) && false ) ? "Y" : "N"; // forced || >= && echo ( true || (true && false) ) ? "Y" : "N"; // forced && > || YNY Edited June 6, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
requinix Posted June 6, 2013 Share Posted June 6, 2013 still dont work and it pass it as if its higher than 25 mb :S, sigh i used that $mp3 = ($_FILES["fileToUpload"]["type"] == "audio/mp3"); $wav = ($_FILES["fileToUpload"]["type"] == "audio/wav"); $mpeg = ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"] <= 70000000); if ($mp3 || $wav || $mpeg) {instead of that part if (($_FILES["fileToUpload"]["type"] == "audio/mp3") || ($_FILES["fileToUpload"]["type"] == "audio/wav") || ($_FILES["fileToUpload"]["type"] == "audio/mpeg") && ($_FILES["fileToUpload"]["size"] >= 26214400) && ($_FILES["fileToUpload"]["size"]<= 70000000) ) { And that's the problem: the part you're using is the one I wrote to try to make it more obvious how your code was working. Working incorrectly. The second thing I posted is what you're supposed to use, but you can use variables (like how I did in the other) if you want to make it easier to read. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 6, 2013 Share Posted June 6, 2013 I agree with requinix regarding the use of variables. Makes your code more readable and easier to modify. If you hard code a minimum file size and have to use it multiple times it would be easy to try and change that minimum size and miss one of the instances. My take: $validFileTypes = array('audio/mp3', 'audio/wav', 'audio/mpeg'); $fileType = $_FILES["fileToUpload"]["type"]; $fileSize = $_FILES["fileToUpload"]["size"]; $minFileSize = 26214400; $maxFileSize = 70000000; if( in_array($fileType, $validFileTypes) && $fileSize >= $minFileSize && $fileSize <= $maxFileSize ) { //Conditions passed } 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.