Are you constantly dealing with files in your PHP projects and struggling with size calculations, storage inconsistencies, or integration with cloud platforms? Say goodbye to the hassle! Introducing FileSizeHandler, a lightweight, flexible, and extensible PHP utility that handles file sizes like a pro. Whether you're working with local files, remote URLs, or cloud storage, this library has got you covered.
In this post, weβll explore what makes FileSizeHandler a must-have library for your PHP projects and how to leverage its powerful features.
π Why You Need FileSizeHandler
Handling file sizes is more than just reading bytes. Different systems measure file sizes differently:
- Binary vs. Decimal Units: OS file systems use binary units (MiB, GiB), while storage manufacturers use decimal (MB, GB). Confusing, right?
- Cross-Platform Challenges: File size interpretations vary across operating systems and storage platforms.
- Cloud and Remote Files: Measuring file sizes from FTP, S3, or Google Cloud often requires additional work or APIs.
FileSizeHandler simplifies all of this by providing a unified, fluent API for file size calculations, formatting, and integrations.
β¨ Features That Make It Shine
- Local, Remote, FTP, and Cloud Support Fetch file sizes seamlessly from:
- Local file systems
- Remote HTTP/HTTPS URLs
- FTP servers
- Amazon S3, Google Cloud Storage, and more!
Binary and Decimal Unit Support
Switch between binary (1024-based) and decimal (1000-based) units
with a single method.Fluent Interface
Chain methods to create clean and readable code.Localization
Format file sizes with localized unit names (e.g., Mio, Kio) for a
better user experience.Extensibility
Easily extend the library with custom sources for specialized file
size calculations.
π οΈ Installation
Install the library using Composer:
composer require nassiry/filesize-handler
π Getting Started
Local File Example
Letβs start with the basics. Fetch the size of a local file in binary units (default):
use Nassiry\FileSizeUtility\FileSizeHandler;
$handler = FileSizeHandler::create()
->local('/path/to/your/file.txt')
->baseBinary();
echo $handler->formattedSize(); // Output: "1.23 MiB"
Switch to decimal units with just one method:
echo $handler->baseDecimal()->formattedSize(); // Output: "1.30 MB"
π‘ Why Developers Love FileSizeHandler
π§ Simplifies File Size Handling
No more juggling different APIs and libraries for local, remote, or cloud file sizes.
π Extensible and Future-Proof
Adding new storage platforms is as simple as creating an extension or implementing an interface.
β‘ Lightweight and Performant
Built for speed and simplicity, with zero unnecessary bloat.
π Learn More
Check out the GitHub Repository for more details, documentation, and examples. and give a STAR if you like it.
Introducing Extensions
The power of FileSizeHandler doesnβt end with the core library. Take your file size handling to the next level with official extensions:
Want to see official extensions in action? Explore them below:
FTP Extension
S3 Extension
Google Cloud Extension
Remote URL Extension
π Get Started Today
With FileSizeHandler, handling file sizes in PHP has never been easier. Install it, extend it, and make your projects smarter and more efficient.
Happy coding! π
Top comments (0)