m2code / file-manager
Flexible Laravel File Manager: upload, move, delete, thumbnail, blurhash, and more
Requires
- php: ^8.2
- ext-http: *
- ext-imagick: *
- illuminate/console: ^10|^11|^12|^13
- illuminate/filesystem: ^10|^11|^12|^13
- illuminate/http: ^10|^11|^12|^13
- illuminate/support: ^10|^11|^12|^13
- intervention/image: ^3
- kornrunner/blurhash: ^1.1
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0|^11.0
README
β οΈ This package is currently under active development. Breaking changes may occur. Contributions are welcome!
π¦ A modular, clean-architecture-based Laravel package to manage file operations β image, video, documents β with support for multiple drivers (local, cloud, Firebase, etc), progressive images, and flexible configuration.
π§ Features
- π Save and delete files (single or batch)
- π§ Auto-detect file type & handle accordingly
- π§Ύ Input-agnostic file handling (
UploadedFile, base64 data URI, raw SVG string) - π Image processing (blurhash, low quality, watermark, optimized AVIF/WebP)
- π§© Structured variants (
original,optimized,low_quality,watermark) - βοΈ Extensible storage drivers: local, S3, Firebase, etc.
- βοΈ Clean architecture (DDD-friendly & testable)
- π§© Facade and fluent Uploader API
- π Support for signed/dynamic URLs
π Installation
composer require m2code/file-manager
π Publish Configuration
php artisan vendor:publish --tag=config --provider="M2code\FileManager\FileManagerServiceProvider"
π Basic Usage
Save file using facade (no config):
use M2code\FileManager\Facades\FileManager; $result = FileManager::save($request->file('image'), 'uploads'); $result->filePath;
Save from base64 or raw SVG string:
use M2code\FileManager\Facades\FileManager; // Base64 PNG $base64Png = 'data:image/png;base64,...'; $png = FileManager::save($base64Png, 'uploads'); // Base64 SVG $base64Svg = 'data:image/svg+xml;base64,...'; $svgFromBase64 = FileManager::save($base64Svg, 'uploads'); // Raw SVG string $svg = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64">...</svg>'; $svgRaw = FileManager::save($svg, 'uploads');
Upload image with processing:
use M2code\FileManager\Application\Uploader\ImageUploader; $result = ImageUploader::make() ->blur() ->lowQuality() ->watermark() ->optimize('avif') // fallback to webp, or skipped if unsupported ->upload($request->file('photo'), 'uploads/images'); $result->variants->get('original')?->path; $result->variants->get('optimized')?->path; $result->variants->get('low_quality')?->path; $result->variants->get('watermark')?->path; $result->blurhash; // Backward-compatible fields (still available): $result->path; $result->optimizedPath; $result->lowQualityPath; $result->watermarkPath;
SVG behavior in ImageUploader
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64">...</svg>'; $result = ImageUploader::make() ->blur() ->lowQuality() ->watermark() ->optimize('avif') ->upload($svg, 'uploads/images'); // SVG only keeps original variant, raster processing is skipped: $result->variants->get('original')?->path; // not null $result->variants->get('low_quality'); // null $result->variants->get('optimized'); // null $result->blurhash; // null
Delete files:
use M2code\FileManager\Facades\FileManager; FileManager::delete('uploads/images/file.jpg'); FileManager::deleteMany([ 'uploads/images/a.jpg', 'uploads/images/b.jpg', ]); // Delete all variants from upload result: FileManager::deleteVariants($result->variants);
π‘ Get file URL
use M2code\FileManager\Facades\FileUrl; $url = FileUrl::getUrl('uploads/images/image.jpg'); // Local or driver-specific $signed = FileUrl::getSignedUrl('uploads/images/image.jpg', now()->addMinutes(5));
π Supported Drivers
- β Local (default)
- π S3, Firebase, Custom drivers
Configure in config/file-manager.php:
'default_driver' => 'local', 'default_deleter' => 'local', 'default_url_generator' => 'local',
π§© Requirement: Imagick
This package uses intervention/image with Imagick driver for image processing features such as:
- Blurhash generation
- Optimized AVIF/WebP variant generation
- Low quality image variants
- Watermark (when enabled)
Imagick is required and declared in composer.json (ext-imagick).
βοΈ Why Imagick?
Compared to GD:
- Better image quality
- Faster processing for large images
- More advanced image manipulation capabilities
If you're serious about handling images, GD isβ¦ let's say, βminimum effort modeβ.
π» Installation Guide
πͺ Windows
-
Download Imagick DLL from: π https://windows.php.net/downloads/pecl/releases/imagick/
-
Choose version that matches:
- Your PHP version
- Thread safety (TS/NTS)
- Architecture (x64/x86)
-
Copy
.dllfile to:ext/ -
Enable in
php.ini:
extension=imagick
- Restart your web server
π macOS
Using Homebrew:
brew install imagemagick pecl install imagick
Then enable in php.ini:
extension=imagick
π§ Linux (Ubuntu/Debian)
sudo apt update sudo apt install imagemagick sudo apt install php-imagick
Restart PHP / Web Server:
sudo service php-fpm restart
# or
sudo service apache2 restart
π§ Linux (CentOS/RHEL)
sudo yum install epel-release sudo yum install ImageMagick ImageMagick-devel sudo pecl install imagick
Enable in php.ini:
extension=imagick
β Verify Installation
Run:
php -m | grep imagick
If installed correctly, you should see:
imagick
β Current Stable Flow
- Upload image (with optional variants)
- Upload from
UploadedFile, base64 data URI, or raw SVG string - Read variant paths from
ImageUploadResult::variants - Generate URL / signed URL
- Delete single file / batch / all variants safely
π License
MIT License Β© Marij Mokoginta (M2code)