แจก Function หาขนาดไฟล์ในโฟลเดอร์ PHP

แจก Function หาขนาดไฟล์ในโฟลเดอร์ PHP 

function format_folder_size($size)

{

 if ($size >= 1073741824)

 {

  $size = number_format($size / 1073741824, 2) . ' GB';

 }

    elseif ($size >= 1048576)

    {

        $size = number_format($size / 1048576, 2) . ' MB';

    }

    elseif ($size >= 1024)

    {

        $size = number_format($size / 1024, 2) . ' KB';

    }

    elseif ($size > 1)

    {

        $size = $size . ' bytes';

    }

    elseif ($size == 1)

    {

        $size = $size . ' byte';

    }

    else

    {

        $size = '0 bytes';

    }

 return $size;

}


function get_folder_size($folder_name)

{

 $total_size = 0;

 $file_data = scandir($folder_name);

 foreach($file_data as $file)

 {

  if($file === '.' or $file === '..')

  {

   continue;

  }

  else

  {

   $path = $folder_name . '/' . $file;

   $total_size = $total_size + filesize($path);

  }

 }

 return format_folder_size($total_size);

}


ตัวอย่างแสดงผล



แจก Function หาขนาดไฟล์ในโฟลเดอร์ PHP แจก Function หาขนาดไฟล์ในโฟลเดอร์ PHP Reviewed by IOffer on กุมภาพันธ์ 07, 2567 Rating: 5

ไม่มีความคิดเห็น:

Blogger Theme Blank Page

  <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html> <html b:version='2' class='v2' ...

ขับเคลื่อนโดย Blogger.