When you provide a link to a file for the user to download, it's sometimes nice to provide the size of the file so that they know what they're getting themselves into.
ASP
function getFileSize(someFile)dim fsdim fileset fs = Server.CreateObject("Scripting.FileSystemObject")set file = fs.GetFile(Server.MapPath(someFile))getFileSize = FormatFileSize(file.size)set file = nothingset fs = nothingend function
The size property returns the size in bytes, which could be a very large number. As you may have guessed, we're going to write a FormatFileSize function to wrap around it.
ASP
function FormatFileSize(size)dim unitsdim factorunits = Array("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")factor = log(size) \ 7FormatFileSize = Round(size / (1024 ^ factor), 2) & units(factor)end function
I think it will be a very, very long time before we reach yottabytes, so this function should withstand the test of time. Next week I'll show you how to get the file type and why you might want that.

No comments:
Post a Comment