Page 1 of 1

Parsing and unparsing file sizes

Posted: Wed Aug 01, 2007 11:49 am
by Kasai
Hey guys,

I'm writing a webpage that has upload capabilities. However, i'm trying to restrict each user's total amount they are allowed to upload. I have decided that the best way is to have a database column with a max limit. Then when they log on or try to upload something, the code will check their total filesize with the databases max and either allow or deny certain functions. However, im having trouble understanding parsed file sizes.

at this point, i can grab the total size of all the files in a certain directory and i hvae it storage as $size. then i put it into a session variable. However, the number that the code spits out is like a 5 digit unparsed number. I then use parse_file_size() and it makes the code into the pretty 7.00 MB . However, when doing arithmetic operations, the 7.00 is what it uses. So what if i were to have someone upload a GB? that would be 1.00 GB and the code would allow if i checked if it was greater that 7.00 MB because the number is smaller.

So my question is this. Is there any way to understand what the parsed number means so that i can use it to do arithmatic operations, or is there like different operations so that i can check the GB vs MB?

Or, am i totally going about this the wrong way?

here is the number unparsed : 8373452
and here it is after passing through parse_file_size() : 7.99 MB

Thanks

just use the byte information

Posted: Wed Aug 01, 2007 12:26 pm
by yacahuma
just is the number of bytes (the long number) for everything
The MB stuff should be for user display only

Posted: Wed Aug 01, 2007 12:53 pm
by Kasai
so the unparsed number is the number of bytes?

and if so, why are there 8 million some odd instead of like a 7 million 990thousand?

Posted: Wed Aug 01, 2007 1:09 pm
by nathanr
1kb = 1024 bytes
1mb = 1024kb
1gb = 1024mb

not 1000... 1024

Posted: Wed Aug 01, 2007 1:13 pm
by Kasai
oh man. im dumb. i forgot eveything is in base 2.lol

thanks guys. i should have this up very soon.