Download the PHP package gungcahyadipp/file-service without Composer
On this page you can find all versions of the php package gungcahyadipp/file-service. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gungcahyadipp/file-service
More information about gungcahyadipp/file-service
Files in gungcahyadipp/file-service
Package file-service
Short Description A Laravel package for handling file operations with support for local and S3 storage
License MIT
Informations about the package file-service
Laravel File Service
A comprehensive Laravel package for handling file operations with support for both local and S3 storage, including image compression capabilities using ImageMagick.
Features
- 🗂️ Support for multiple storage disks (local, S3)
- 🖼️ Image compression with configurable quality and dimensions
- 📦 Base64 image handling
- 🏷️ Smart file naming with slug generation
- 🔄 Complete file information return (size, MIME type, URL, etc.)
- ⚙️ Configurable path structures for different storage types
- 🎯 Laravel facade support for easy usage
Requirements
- PHP >= 8.1
- Laravel >= 9.0
- ImageMagick extension (optional, for image compression)
Installation
Install the package via Composer:
Laravel Auto-Discovery
The package will automatically register its service provider and facade.
Manual Registration (if needed)
Add the service provider to your config/app.php:
Add the facade to your config/app.php:
Publish Configuration
Publish the configuration file:
Configuration
The package configuration file config/file-service.php allows you to customize:
- Default storage disk
- Path structures for different disks
- Image compression settings
- File naming conventions
- Temporary directory location
Environment Variables
You can set these environment variables in your .env file:
Usage
Basic File Operations
Using Dependency Injection
Advanced File Operations
Complete File Information
The saveFileComplete method returns comprehensive file information:
Base64 Image Handling
Image Compression
Enable automatic image compression for uploaded images:
Manual image compression:
Storage Disk Configuration
Using Different Disks
Path Structure
The package automatically handles different path structures:
- S3:
filemanager/{folder}/{filename} - Local:
{folder}/{filename}
Error Handling
All methods include proper error handling and logging:
API Reference
Methods
getFile(string $folder, string $fileName): ?string
Returns the URL of a file or null if it doesn't exist.
saveFile(UploadedFile $file, string $folder, string $fileName): string
Saves an uploaded file and returns the generated filename.
deleteFile(string $folder, string $fileName): bool
Deletes a file and returns success status.
saveBase64Image(string $base64Image, string $folder, string $fileName): string|false
Saves a Base64 encoded image and returns the filename or false on failure.
saveFileComplete(UploadedFile $file, string $folder, string $fileName, bool $is_compressed = false): array
Saves a file with complete metadata and optional compression.
deleteFileFullPath(string $path): bool
Deletes a file using its full path.
compressImage(string $pathImage, int $compressionQuality = 70, int $newMaxWidth = 1200, int $newMaxHeight = 1200): void
Compresses an image file using ImageMagick.
scaleImage(int $x, int $y, int $cx, int $cy): array
Calculates new dimensions for image scaling while maintaining aspect ratio.
Testing
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG.md for details on what has changed.
Support
If you find this package useful, please consider starring it on GitHub!
All versions of file-service with dependencies
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
illuminate/filesystem Version ^8.0|^9.0|^10.0|^11.0
symfony/http-foundation Version ^5.0|^6.0|^7.0