In PHP, the size of the file can be obtained through the FileSize function, and the file size is expressed as a number of bytes. If you want to convert the units of a file size, you can define your own function to implement it.

Source: Internet
Author: User
Tags vars

Tag: File conversion resource BER definition echo func file size Art

  1. <?php
  2. function GetSize ($size, $format) {
  3. $p = 0;
  4. if ($format = = ' KB ') {
  5. $p = 1;
  6. } elseif ($format = = ' mb ') {
  7. $p = 2;
  8. } elseif ($format = = ' GB ') {
  9. $p = 3;
  10. }
  11. $size/= Pow (1024x768, $p);
  12. return Number_format ($size, 3);
  13. }
  14. $filename = '/data/webroot/usercode/code/resource/test.txt ';
  15. $size = filesize ($filename);
  16. $size = GetSize ($size, ' KB '); //For unit conversions
  17. Echo $size.'  KB ';

In PHP, the size of the file can be obtained through the FileSize function, and the file size is expressed in bytes. If you want to convert the units of a file size, you can define your own function to implement it.

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.