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 Link to comment https://forums.phpfreaks.com/topic/115490-bytes-to-megabytes/ 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 Link to comment https://forums.phpfreaks.com/topic/115490-bytes-to-megabytes/#findComment-593730 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; Link to comment https://forums.phpfreaks.com/topic/115490-bytes-to-megabytes/#findComment-593732 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. Link to comment https://forums.phpfreaks.com/topic/115490-bytes-to-megabytes/#findComment-593899 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! Link to comment https://forums.phpfreaks.com/topic/115490-bytes-to-megabytes/#findComment-594154 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 Link to comment https://forums.phpfreaks.com/topic/115490-bytes-to-megabytes/#findComment-594156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.