= 1073741824) {
return round($size / 1073741824, 2) . ' GB';
} elseif ($size >= 1048576) {
return round($size / 1048576, 2) . ' MB';
} elseif ($size >= 1024) {
return round($size / 1024, 2) . ' KB';
} else {
return $size . ' B';
}
}
/**
* 获取文件类型图标
*
* @param string $type 文件类型
* @return string 图标HTML
*/
public function getFileTypeIcon(string $type)
{
$type = strtolower($type);
$icons = [
'pdf' => '',
'doc' => '',
'docx' => '',
'xls' => '',
'xlsx' => '',
'ppt' => '',
'pptx' => '',
'jpg' => '',
'jpeg' => '',
'png' => '',
'gif' => '',
'webp' => '',
'zip' => '',
'rar' => '',
'txt' => '',
];
return $icons[$type] ?? '';
}
/**
* 检查文件是否为图片
*
* @param string $type 文件类型
* @return bool 是否为图片
*/
public function isImage(string $type)
{
$type = strtolower($type);
$imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
return in_array($type, $imageTypes);
}
}