且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过URL调整图像文件的大小?

更新时间:2023-02-23 19:12:25

使用 filesize 这样的功能:

Use filesize function like this:

echo filesize($filename) . ' bytes';

您还可以使用此功能设置尺寸单位的格式:

You can also format the unit of the size with this function:

function format_size($size) {
      $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
      if ($size == 0) { return('n/a'); } else {
      return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
}