PHP filesize MB/KB conversion [duplicate]

Here is a sample: <?php // Snippet from PHP Share: http://www.phpshare.org function formatSizeUnits($bytes) { if ($bytes >= 1073741824) { $bytes = number_format($bytes / 1073741824, 2) . ‘ GB’; } elseif ($bytes >= 1048576) { $bytes = number_format($bytes / 1048576, 2) . ‘ MB’; } elseif ($bytes >= 1024) { $bytes = number_format($bytes / 1024, 2) … Read more

Get size of file on disk

This uses GetCompressedFileSize, as ho1 suggested, as well as GetDiskFreeSpace, as PaulStack suggested, it does, however, use P/Invoke. I have tested it only for compressed files, and I suspect it does not work for fragmented files. public static long GetFileSizeOnDisk(string file) { FileInfo info = new FileInfo(file); uint dummy, sectorsPerCluster, bytesPerSector; int result = GetDiskFreeSpaceW(info.Directory.Root.FullName, … Read more