Just had a bit of a problem today dealing with displaying file sizes of uploaded reports in an application we are upgrading using Zend Framework. When the files are uploaded, the file sizes are stored in bytes, but for display we need to show the sized in KB as the typical file size is between 60k and 2,048KB (2MB).
Looking through http://php.net I came across some scripts that we could use, but I was looking for a versatile re-useable solution. Well that is when I came across Zend_Measure (http://www.framework.zend.com/manual/en/zend.measure.html).
How did we use it, well, very simply:
- Added Zend_Measure library files into our application library folder (we do not install all components by default, we add them as we need to)
- Created a new Zend_Measure_Binary (http://www.framework.zend.com/manual/en/zend.measure.types.html) class instance
- Add the filesize in bytes
- Change the type from bytes to kilobytes (the conversion types are available as constants)
- Call the toString() method to output the formatted type
Now we have a reusable element which can be used …