tourze/easy-admin-file-size-field-bundle
Composer 安装命令:
composer require tourze/easy-admin-file-size-field-bundle
包简介
A Symfony bundle that provides a file size field for EasyAdmin, automatically formatting byte values into human-readable formats
README 文档
README
A Symfony bundle that provides a file size field for EasyAdmin, automatically formatting byte values into human-readable formats (KB, MB, GB, etc.).
Features
- Automatic formatting: Converts raw byte values into human-readable formats (B, KB, MB, GB, TB)
- Twig integration: Provides a
format_bytesfilter for use in templates - Easy integration: Works seamlessly with EasyAdmin's field system
- Customizable: Supports all standard EasyAdmin field options
Installation
Install the bundle using Composer:
composer require tourze/easy-admin-file-size-field-bundle
Quick Start
In your EasyAdmin CRUD controller, use the FileSizeField to display file sizes:
<?php namespace App\Controller\Admin; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use Tourze\EasyAdminFileSizeFieldBundle\Field\FileSizeField; use App\Entity\File; class FileCrudController extends AbstractCrudController { public static function getEntityFqcn(): string { return File::class; } public function configureFields(string $pageName): iterable { return [ IdField::new('id'), TextField::new('name'), FileSizeField::new('size', 'File Size'), ]; } }
Usage
In EasyAdmin Controllers
// Basic usage FileSizeField::new('fileSize') // With custom label FileSizeField::new('fileSize', 'Document Size') // With additional options FileSizeField::new('fileSize', 'Size') ->setHelp('The size of the uploaded file') ->hideOnIndex()
In Twig Templates
You can also use the format_bytes filter directly in your Twig templates:
{{ file.size|format_bytes }}
{# Output: "1.5 MB" #}
{{ 1024|format_bytes }}
{# Output: "1 KB" #}
Advanced Usage
Custom Formatting Options
The FileSizeField supports additional configuration options:
FileSizeField::new('fileSize') ->setTemplatePath('admin/custom_file_size.html.twig') ->addCssClass('file-size-custom') ->setFormTypeOptions([ 'precision' => 2, 'binary' => true, // Use 1024 instead of 1000 as base ])
Form Type Integration
You can also use the form type directly in your forms:
use Tourze\EasyAdminFileSizeFieldBundle\Form\FileSizeType; public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('maxFileSize', FileSizeType::class, [ 'label' => 'Maximum File Size', ]) ; }
Configuration
The bundle registers itself automatically when installed. No additional configuration is required.
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- EasyAdmin 4.0 or higher
License
This bundle is released under the MIT license. See the LICENSE file for details.
tourze/easy-admin-file-size-field-bundle 适用场景与选型建议
tourze/easy-admin-file-size-field-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 235 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/easy-admin-file-size-field-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/easy-admin-file-size-field-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 235
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-07