PHPackages                             ygthor/laravel-file-handler - 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. ygthor/laravel-file-handler

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

ygthor/laravel-file-handler
===========================

For handle S3 and file using drupal's file approach

028PHP

Since Jan 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ygthor/laravel-file-handler)[ Packagist](https://packagist.org/packages/ygthor/laravel-file-handler)[ RSS](/packages/ygthor-laravel-file-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Documentation
=============

[](#documentation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c59a87214c4a85eaf353d296522aca6c09c79236907ad4d5ae0f8feb94c5aed1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796774686f722f6c61726176656c2d66696c652d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ygthor/laravel-file-handler)[![Total Downloads](https://camo.githubusercontent.com/c82bacaa072fc4644e17db75fb88b61ae402a664bf8062c344e98feb471e5fc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796774686f722f6c61726176656c2d66696c652d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ygthor/laravel-file-handler)[![GitHub Actions](https://github.com/ygthor/laravel-file-handler/actions/workflows/main.yml/badge.svg)](https://github.com/ygthor/laravel-file-handler/actions/workflows/main.yml/badge.svg)

- Tested on Laravel 8
- Hard-coded to use storage 's3' only

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

[](#installation)

You can install the package via composer:

```
composer require ygthor/laravel-file-handler
```

### Table to add

[](#table-to-add)

```
CREATE TABLE `file_handles` (
  `fid` bigint(20) UNSIGNED NOT NULL,
  `filename` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `filepath` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_ext` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `filemine` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `filesize` int(11) DEFAULT NULL,
  `disk` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `model_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `model_primary_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `model_column` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uploader_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `file_handles` ADD PRIMARY KEY (`fid`);
ALTER TABLE `file_handles` MODIFY `fid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
```

### .env to set

[](#env-to-set)

```
AWS_ACCESS_KEY_ID="GET_FROM_OBJECT_STORAGE"
AWS_SECRET_ACCESS_KEY="GET_FROM_OBJECT_STORAGE"
AWS_DEFAULT_REGION="ap-south-1"
AWS_BUCKET="my-bucket"
AWS_ENDPOINT="https://ap-south-1.linodeobjects.com"
AWS_USE_PATH_STYLE_ENDPOINT=false

```

### update config/filesystems.php (if not match)

[](#update-configfilesystemsphp-if-not-match)

```
's3' => [
    'driver' => 's3',
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'region' => env('AWS_DEFAULT_REGION'),
    'bucket' => env('AWS_BUCKET'),
    'url' => env('AWS_URL'),
    'endpoint' => env('AWS_ENDPOINT'),
    'bucket_endpoint' => false,
    'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],

```

Functions available
-------------------

[](#functions-available)

```
function setDisk($disk='s3'){}

function setFilename($value){}

function setContent($value){}

# set all variable object, use together with upload() function
function set($arr){}
	$arr = [
		'disk' => '', //default s3
		'filename' => '', //required
		'content' => '',  //required, data from file_get_contents()
		'model_name' => '', // optional, for ease in reverse checking
		'model_primary_key' => '', // optional, for ease in reverse checking
		'model_column' => '', // optional, for ease in reverse checking
		'uploader_name' => '', // optional, for ease in reverse checking
		'status' => '', // default permanent, if is temporary, file will delete automatically after specific time (feature still In DEV)
	];

# use after set()
function upload($filename=null, $content=null){}

# check file exist in S3 server
function exists($filename){}

# delete file in file_handles and S3 server
function delete($fid){}

function getS3Path($fid=5){}
function getS3Url($fid=5){}
function getS3UrlByPath('path/to/file'){}
```

Sample Usage
------------

[](#sample-usage)

- Need to add column such as fid\_photo, fid\_photo\_2 in source table to store fid

```
...
use LaravelFileHandler;
...
class TestController{
	...
	function save(){
		$profile_image = $request->file('profile_image');
		$user_id = auth()->id();

		$file_handle = LaravelFileHandler::set([
			'filename' => 'optional_image_path/' . $user_id . '/profile',
			'content' => $profile_image,
			'model_name' => '\App\Models\User',
			'model_primary_key' => 'id',
			'model_column' => 'profile_photo_fid',
			'uploader_name' => auth()->user()->name,
		])->upload();

		User::find($user_id)->fill(['photo_fid' => $file_handle->fid])->save();
	}
	...
}
```

Some Helper functions for S3
----------------------------

[](#some-helper-functions-for-s3)

```
# Helper Function to retrieve file on S3

$path =  LaravelFileHandler::getS3Path($fid=5);
$s3_file_url =  LaravelFileHandler::getS3Url($fid=5);
$s3_file_url =  LaravelFileHandler::getS3UrlByPath('path/to/file');

$is_exists = LaravelFileHandler::exists($file_path);

 //return true if delete success
 //retrun false if fid not found / path not found
$status = LaravelFileHandler::delete($fid=5);

# if you are not using 's3' in config
# you need to use setDisk function
$s3_file_url = LaravelFileHandler::setDisk('s3')->getS3Path($fid=5)

```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

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

Credits
-------

[](#credits)

- [YG Thor](https://github.com/ygthor)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/882772b25ca46f7693fafd884e81fd35f09e0bb4c3132b662a3afa6230c0a131?d=identicon)[ygthor](/maintainers/ygthor)

---

Top Contributors

[![ygthor](https://avatars.githubusercontent.com/u/51053902?v=4)](https://github.com/ygthor "ygthor (1 commits)")

### Embed Badge

![Health badge](/badges/ygthor-laravel-file-handler/health.svg)

```
[![Health](https://phpackages.com/badges/ygthor-laravel-file-handler/health.svg)](https://phpackages.com/packages/ygthor-laravel-file-handler)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M123](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M61](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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