Using File.size(myfile) I can get the size of the uploaded file in _bytes_. Does anybody know of a function to convert bytes into a more human readable format? If I had a wish list for a "file_size_in_words()" function, it would do this: 10752 bytes becomes "10.5 Kilobytes". 2213814 bytes becomes "2.1 Megabytes". 238 bytes becomes "Less Than 1 Kilobyte". Maybe I need to learn how to write a plug-in and figure it out! Or maybe somebody has done this and can point me in the right direction. Thanks! Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060529/b0e585c3/attachment.html
Jeff Ward wrote:> Using File.size(myfile) I can get the size of the uploaded file in > _bytes_. > > Does anybody know of a function to convert bytes into a more human > readable format?Perhaps the human_size helper is what you''re looking for? http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html Loading development environment. >> include ActionView::Helpers::NumberHelper => Object >> i = 123456 => 123456 >> human_size i => "120.6 KB" hope that helps, guess you''ll have to focus your plugin energies upwards and onwards ;) -phil -- Phillip Kast (909)630-9562 phil@unimedia.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060529/723c63eb/attachment.html
Yes! This will do the trick! Thanks. On 5/28/06, Phillip Kast <phil@unimedia.org> wrote:> > Jeff Ward wrote: > > Using File.size(myfile) I can get the size of the uploaded file in > _bytes_. > > Does anybody know of a function to convert bytes into a more human > readable format? > > Perhaps the human_size helper is what you''re looking for? > http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html > > Loading development environment. > >> include ActionView::Helpers::NumberHelper > => Object > >> i = 123456 > => 123456 > >> human_size i > => "120.6 KB" > > hope that helps, > guess you''ll have to focus your plugin energies upwards and onwards ;) > > -phil > > -- > Phillip Kast > (909)630-9562 > phil@unimedia.org > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060529/6091c705/attachment.html