Vivid Lust Posted July 18, 2008 Share Posted July 18, 2008 I have this script $dir = "../uploads/"; $size_in_bytes = disk_total_space($dir); How can i convert the $size_in_bytes into mega bytes??? Thanks all Quote Link to comment Share on other sites More sharing options...
corbin Posted July 18, 2008 Share Posted July 18, 2008 Basic math. 1024 B in a KB. 1024KB in a MB. $number = $number/1048576; //B divided by 1024*1024 Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted July 18, 2008 Author Share Posted July 18, 2008 So its: $dir = "../uploads/"; $size_in_bytes = disk_total_space($dir); $mb = $size_in_bytes / 1048576; Quote Link to comment Share on other sites More sharing options...
Stephen Posted July 18, 2008 Share Posted July 18, 2008 Did you try it? It should work. You might also want to round it to the nearest hundredth. Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted July 19, 2008 Author Share Posted July 19, 2008 It doesnt work :s Bytes: 747134910464 Megabytes: 712523.375 And my host says ive only used 3.89 of storage ??? Please help! Quote Link to comment Share on other sites More sharing options...
flappy_warbucks Posted July 19, 2008 Share Posted July 19, 2008 function sort_bytes($bytes) //send down a vairable that contains the number of bytes. { $size = $bytes / 1024; if($size < 1024) { $size = number_format($size, 2); $size .= ' <i>KB</i>'; } else { if($size / 1024 < 1024) { $size = number_format($size / 1024, 2); $size .= ' <i>MB</i>'; } else if ($size / 1024 / 1024 < 1024) { $size = number_format($size / 1024 / 1024, 2); $size .= ' <i>GB</i>'; } } return $size; } that should do it for you 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.