Jump to content

Problem Checking File Size if else statement


kasitzboym

Recommended Posts

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

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

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.

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 />';
    }

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 />';
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.