PHP file size Formatting Function

Source: Internet
Author: User

 

<? Php <br/>/** <br/> * Capacity formatting <br/> * recoded by androidyue <br/> * @ Param string file name (file path) <br/> * @ return if the file exists, the formatted string is returned. If an error occurs, the unknown file is returned. <br/> */<br/> function sizeformat ($ filename) {<br/> // obtain the file size <br/> @ $ filesize = filesize ($ filename ); <br/> // error message returned if the file does not exist <br/> If (false = $ filesize) {<br/> return 'unknown file '; <br/>}< br/> // format the file size information <br/> if ($ filesize> = 1073741824) $ filesize = round ($ fil Esize/1073741824*100)/100. 'gb'; <br/> elseif ($ filesize> = 1048576) $ filesize = round ($ filesize/1048576*100)/100. 'mb '; <br/> elseif ($ filesize> = 1024) $ filesize = round ($ filesize/1024*100)/100. 'kb'; <br/> else $ filesize = $ filesize. 'bytes '; <br/> return $ filesize; <br/>}< br/> // test the function <br/> echo sizeformat ('config. inc. PHP '); <br/>?> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.