Saved Bookmarks
| 1. |
Solve : PHP is not finding correct dir size (%)? |
|
Answer» I am trying to make this PHP code echo the % of space used. (%/100) It doesn't work. Code: [Select]function roundsize($size){ $i=0; $iec = array("B", "Kb", "Mb", "Gb", "Tb"); while (($size/1024)>1) { $size=$size/1024; $i++;} return(round($size,1)." ".$iec[$i]);} $user = $_COOKIE['usernamm']; $WEB = file_get_contents("system/web_$user.txt"); $space = disk_total_space("$web/"); $space = $space; $space = roundsize($space); echo "$space%";I think it MIGHT be because of $space%. Try echo "{$space}%";No, I just don't know how to actully "get" the % from 100.. Any clue?Output (Bites) 2141653.08% It needs to be $space/100 into a %.Is this a maths question?!I don't know how to get the file size in php and make it a percentage...I mean directory size XDdivide the size of the item your acquiring the percentage for by the total size. and then if you want to get the space not used by that item, SUBTRACT the resulting number from 1. For example if you have a 5MB file on a 1GB drive, that's 5/1024=0.48828125%.Okay. So, this will work ? Code: [Select] $space = disk_total_space("$web/"); $space = $space / disk_free_space("$web/"); echo $space; Quote from: Rob Pomeroy on June 12, 2009, 03:20:47 PM Is this a maths question?!.. Yes. . Sorry, we don't have a maths forum Rob, Banana97 obviously doesn't know the code or the function in PHP to do what he wants to, so he has asked you how to do it - not keep REPEATING the same thing over.looks to me, like he knew all the functions he needed. Just didn't know the percentage formula. |
|