kasitzboym Posted December 25, 2011 Share Posted December 25, 2011 I am trying to check to see if a file size is acceptable before an upload but cant seem to get the right result no matter what i do. if i have my if statement below coded like this if($_FILES["upload"]["size"] < 1024000){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } Then i always am entereing the if statememnt but if i have my if statement like this if($_FILES["upload"]["size"] > 1024000){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } then i always seem to enter the else staement. I have tried with a VIREITY of differnt size files some from like 2kb to 10mb... i believe somewhere near the > or < is my problem but i dont seem to see it Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/ Share on other sites More sharing options...
melloorr Posted December 25, 2011 Share Posted December 25, 2011 How about using the filesize() function: $filename = 'somefile.txt'; if(filesize($filename) < 1024000){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } Just use variables or a form to get the file Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/#findComment-1301225 Share on other sites More sharing options...
kasitzboym Posted December 25, 2011 Author Share Posted December 25, 2011 Thanks but im having more trouble with this than i am with my if else statement... If i take out the statement and just echo $_FILES["upload"]["size"] then it prints out the file size every time its just when i have it in an if statement that it has trouble. Any other ideas? i really would like to use this setup. Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/#findComment-1301227 Share on other sites More sharing options...
melloorr Posted December 25, 2011 Share Posted December 25, 2011 Thanks but im having more trouble with this than i am with my if else statement... If i take out the statement and just echo $_FILES["upload"]["size"] then it prints out the file size every time its just when i have it in an if statement that it has trouble. Any other ideas? i really would like to use this setup. Hmm not sure. If you are getting the right size when you use echo, then how about putting it in a variable, then calling the variable? $file = $_FILES["upload"]["size"]; if($file < 1024000){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/#findComment-1301228 Share on other sites More sharing options...
kasitzboym Posted December 25, 2011 Author Share Posted December 25, 2011 You know what i figured figured it out... i dont know why but it didnt like the number in the if statement i changed it to this and i had the variable set like $size = $_FILES["upload"]["size"]; i just type it like that when i was on here... but changing it to a variable seamed to have worked... ill have to do more reading on it maybe it is a bug in PHP they haven't found yet or something... But Anyway thanks for the help!!! $size = $_FILES["upload"]["size"]; $max_file_size = 1024000; if($size > $max_file_size){ echo'entered if statement<br />'; } else{ echo'entered else statement<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/#findComment-1301229 Share on other sites More sharing options...
melloorr Posted December 25, 2011 Share Posted December 25, 2011 Glad you solved it. Merry Christmas! Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/#findComment-1301230 Share on other sites More sharing options...
kasitzboym Posted December 25, 2011 Author Share Posted December 25, 2011 Merry Christmas to you to!!!! Quote Link to comment https://forums.phpfreaks.com/topic/253813-problem-checking-file-size-if-else-statement/#findComment-1301231 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.