PHPackages                             gungcahyadipp/file-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. gungcahyadipp/file-service

ActiveLibrary[File &amp; Storage](/categories/file-storage)

gungcahyadipp/file-service
==========================

A Laravel package for handling file operations with support for local and S3 storage

v1.0(4mo ago)02MITPHPPHP ^8.0

Since Dec 24Pushed 4mo agoCompare

[ Source](https://github.com/gungcahyadipp/file-service)[ Packagist](https://packagist.org/packages/gungcahyadipp/file-service)[ RSS](/packages/gungcahyadipp-file-service/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel 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
--------

[](#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
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 9.0
- ImageMagick extension (optional, for image compression)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require gungcahyadipp/file-service
```

### Laravel Auto-Discovery

[](#laravel-auto-discovery)

The package will automatically register its service provider and facade.

### Manual Registration (if needed)

[](#manual-registration-if-needed)

Add the service provider to your `config/app.php`:

```
'providers' => [
    // ...
    GungCahyadiPP\FileService\Providers\FileServiceProvider::class,
],
```

Add the facade to your `config/app.php`:

```
'aliases' => [
    // ...
    'FileService' => GungCahyadiPP\FileService\Facades\FileService::class,
],
```

### Publish Configuration

[](#publish-configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=file-service-config
```

Configuration
-------------

[](#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

[](#environment-variables)

You can set these environment variables in your `.env` file:

```
FILE_SERVICE_DEFAULT_DISK=local
FILE_SERVICE_COMPRESSION_QUALITY=70
FILE_SERVICE_MAX_WIDTH=1200
FILE_SERVICE_MAX_HEIGHT=1200
```

Usage
-----

[](#usage)

### Basic File Operations

[](#basic-file-operations)

```
use GungCahyadiPP\FileService\Facades\FileService;

// Get file URL
$url = FileService::getFile('documents', 'my-file.pdf');

// Save uploaded file
$fileName = FileService::saveFile($uploadedFile, 'images', 'my-image');

// Delete file
$deleted = FileService::deleteFile('images', 'my-image.jpg');
```

### Using Dependency Injection

[](#using-dependency-injection)

```
use GungCahyadiPP\FileService\FileService;

class DocumentController extends Controller
{
    protected $fileService;

    public function __construct(FileService $fileService)
    {
        $this->fileService = $fileService;
    }

    public function upload(Request $request)
    {
        $file = $request->file('document');
        $fileName = $this->fileService->saveFile($file, 'documents', 'my-document');

        return response()->json(['filename' => $fileName]);
    }
}
```

### Advanced File Operations

[](#advanced-file-operations)

#### Complete File Information

[](#complete-file-information)

The `saveFileComplete` method returns comprehensive file information:

```
$fileInfo = FileService::saveFileComplete(
    $uploadedFile,
    'images',
    'profile-picture',
    true // Enable compression
);

// Returns:
// [
//     'title' => 'profile-picture',
//     'name' => 'profile-picture-abc1.jpg',
//     'path' => 'images/profile-picture-abc1.jpg',
//     'size' => 1024000,
//     'mime_type' => 'image/jpeg',
//     'ext' => 'jpg',
//     'disk' => 'local',
//     'url' => 'http://localhost/storage/images/profile-picture-abc1.jpg'
// ]
```

#### Base64 Image Handling

[](#base64-image-handling)

```
$base64Image = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIA...';
$fileName = FileService::saveBase64Image($base64Image, 'avatars', 'user-avatar');

if ($fileName) {
    echo "Image saved as: " . $fileName;
} else {
    echo "Failed to save image";
}
```

#### Image Compression

[](#image-compression)

Enable automatic image compression for uploaded images:

```
// Compress images automatically during upload
$fileInfo = FileService::saveFileComplete(
    $uploadedFile,
    'thumbnails',
    'product-image',
    true // Enable compression
);
```

Manual image compression:

```
FileService::compressImage(
    '/path/to/image.jpg',
    85,    // Quality (1-100)
    800,   // Max width
    600    // Max height
);
```

### Storage Disk Configuration

[](#storage-disk-configuration)

#### Using Different Disks

[](#using-different-disks)

```
use GungCahyadiPP\FileService\FileService;

// Use specific disk
$s3FileService = new FileService('s3');
$localFileService = new FileService('local');

// Save to S3
$s3FileName = $s3FileService->saveFile($file, 'documents', 'contract');

// Save to local storage
$localFileName = $localFileService->saveFile($file, 'temp', 'upload');
```

#### Path Structure

[](#path-structure)

The package automatically handles different path structures:

- **S3**: `filemanager/{folder}/{filename}`
- **Local**: `{folder}/{filename}`

### Error Handling

[](#error-handling)

All methods include proper error handling and logging:

```
$fileName = FileService::saveFile($uploadedFile, 'images', 'photo');

if ($fileName) {
    // File saved successfully
    $url = FileService::getFile('images', $fileName);
} else {
    // Handle upload failure
    Log::error('Failed to upload file');
}
```

API Reference
-------------

[](#api-reference)

### Methods

[](#methods)

#### `getFile(string $folder, string $fileName): ?string`

[](#getfilestring-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`

[](#savefileuploadedfile-file-string-folder-string-filename-string)

Saves an uploaded file and returns the generated filename.

#### `deleteFile(string $folder, string $fileName): bool`

[](#deletefilestring-folder-string-filename-bool)

Deletes a file and returns success status.

#### `saveBase64Image(string $base64Image, string $folder, string $fileName): string|false`

[](#savebase64imagestring-base64image-string-folder-string-filename-stringfalse)

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`

[](#savefilecompleteuploadedfile-file-string-folder-string-filename-bool-is_compressed--false-array)

Saves a file with complete metadata and optional compression.

#### `deleteFileFullPath(string $path): bool`

[](#deletefilefullpathstring-path-bool)

Deletes a file using its full path.

#### `compressImage(string $pathImage, int $compressionQuality = 70, int $newMaxWidth = 1200, int $newMaxHeight = 1200): void`

[](#compressimagestring-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`

[](#scaleimageint-x-int-y-int-cx-int-cy-array)

Calculates new dimensions for image scaling while maintaining aspect ratio.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Gung Cahyadi](https://github.com/gungcahyadipp)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for details on what has changed.

Support
-------

[](#support)

If you find this package useful, please consider starring it on GitHub!

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance74

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

139d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cbda56e103385dea9039efb6de5c23089bfb8a024dd76985e42a5ecf5fcecef0?d=identicon)[gungcahyadipp](/maintainers/gungcahyadipp)

---

Top Contributors

[![gungcahyadipp](https://avatars.githubusercontent.com/u/30739832?v=4)](https://github.com/gungcahyadipp "gungcahyadipp (2 commits)")

---

Tags

laravels3filestorageuploadimage-compression

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gungcahyadipp-file-service/health.svg)

```
[![Health](https://phpackages.com/badges/gungcahyadipp-file-service/health.svg)](https://phpackages.com/packages/gungcahyadipp-file-service)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[mwguerra/filemanager

A full-featured file manager package for Laravel and Filament v5 with dual operating modes, drag-and-drop uploads, S3/MinIO support, and comprehensive security features.

718.5k1](/packages/mwguerra-filemanager)[zing/laravel-flysystem-obs

Flysystem Adapter for OBS

1211.2k](/packages/zing-laravel-flysystem-obs)[innoge/laravel-rclone

A sleek PHP wrapper around rclone with Laravel-style fluent API syntax

174.1k](/packages/innoge-laravel-rclone)[erlandmuchasaj/laravel-file-uploader

A simple package to help you easily upload files to your laravel project.

128.7k](/packages/erlandmuchasaj-laravel-file-uploader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
