PHPackages                             abianbiya/filehandler - 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. abianbiya/filehandler

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

abianbiya/filehandler
=====================

Filehandler for storing and versioning files in Laravel

1.2(1y ago)032MITPHPPHP ^8.0|^8.1|^8.2|^8.3

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/abianbiya/filehandler)[ Packagist](https://packagist.org/packages/abianbiya/filehandler)[ Docs](https://github.com/abianbiya/filehandler)[ RSS](/packages/abianbiya-filehandler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Abianbiya/Filehandler
=====================

[](#abianbiyafilehandler)

[![Latest Version on Packagist](https://camo.githubusercontent.com/de61baccd058aeeb688b1b433ddbf970b40490d34c4a3a2151977ed2510e1249/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f647369756e6e65732f66696c6568616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dsiunnes/filehandler)[![Total Downloads](https://camo.githubusercontent.com/2302f5fe89d55a1603336e966ba5101ebe3bb0380f539bf40d197ccbbe92cbd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f647369756e6e65732f66696c6568616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dsiunnes/filehandler)[![Build Status](https://camo.githubusercontent.com/e19e3569d9e829b62c923c183635dad411c77996a6f95477b0ca1c38a326bb8a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f647369756e6e65732f66696c6568616e646c65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/dsiunnes/filehandler)

Simple package for handling upload file and versioning to local disk or AWS S3.

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

[](#installation)

Via Composer

```
$ composer require abianbiya/filehandler
```

Usage
-----

[](#usage)

#### Main todo

[](#main-todo)

1. Make your model (that gonna have attached file into it) implements `HasFile` and use `InteractsWithFile` trait
2. That's it.

#### Configure the default disk

[](#configure-the-default-disk)

1. Set `FILESYSTEM_DISK` env variable (local or s3)
2. Fill the configuration detail if you use s3 ```
    AWS_ACCESS_KEY_ID=
    AWS_SECRET_ACCESS_KEY=
    AWS_DEFAULT_REGION=ap-southeast-3
    AWS_BUCKET=

    ```

### Storing file

[](#storing-file)

#### Storing uploaded file from request

[](#storing-uploaded-file-from-request)

1. Set your request validation
2. Catch the file field by calling the model and then save it ```
    $model->addFileFromRequest('fieldname', 'foldername')->save();
    ```

    - fieldname is the form `name`
    - foldername is.. you know, the *kind* of file or whatever that categories the file into some sh\*t (actually this will be used as the folder name in the storage)

#### Storing file from path

[](#storing-file-from-path)

```
$model->addFileFromPath('path', 'foldername')->save();
```

- path is the path
- foldername is.. you know, the `kind` of file or whatever that categories the file into some sh\*t (actually this will be used as the folder name in the storage)

#### Setting file properties

[](#setting-file-properties)

Set some properties to the model's attached file with this function right before `->addFileFrom{What}` called.

```
$model->disk('local')->setProperties($array)->replace()->addFileFrom
```

- `disk()` for specifying the disk, default disk is env FILESYSTEM\_DISK
- `setProperties()` for additional information, put array here, this'll be store as json
- `replace()` if the model has only one file stored to specified folder, then on update we can call this

### Retrieving the file

[](#retrieving-the-file)

Access the file with adding the `file` or `files` eager loading ORM relation to you model. `file` function stands for the single attached file and `files` for multiple files.

```
$data['yuhu'] = Model::with('file')->whateverQueryYouWant();
```

this relation return MediaFile object instance so you can filter it using collection for multiple files or do some operation such as:

```
	@foreach($data as $item)
		$item->file->getPath(); // returns absolute path to the file
		$item->file->getUrl(); // returns direct url path without domain
		$item->file->getFullUrl(); // returns direct full url with domain, recommended for showing file inside html
		$item->file->getMaskedUrl(); // returns masked url with slug routing, recommended for file direct access
		$item->file->getThumbnail(int $width); // * returns  html tag (with lightbox) for image mimetype or a href link for others, can be used to render image or link inside table.
	@endforeach
```

- Publish asset to use lightbox within getThumbnail() method

```
$ php artisan vendor:publish --tag=filehandler.assets
```

then load the assets

```

```

additional option for wrapping file upload form with drag-and-drop input

```

```

then use class `.dropify`

### Intercepting File Access (using masked URL)

[](#intercepting-file-access-using-masked-url)

The default access to the file is `true`, otherwise you would like to add a gate to the masked URL route, add this method into your implemented InteractsWithFile model:

```
public function canAccessFile() : array|bool
{
	// do some complicated checking algorithm to authorized role or file ownership
	// you may use Auth::user(), or $this->created_by to check this model record's owner, or whatever
	return $allowAccess; // returning boolean
	// OR
	return [$allowAccess, 'Such a denied message to show in a 403 page']; // returning array (default message: Forbidden.)
}
```

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please poke me at @abianbiya (wherever) instead of using the issue tracker.

Credits
-------

[](#credits)

- [Abi Anbiya](https://github.com/abianbiya)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance45

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Every ~144 days

Total

3

Last Release

427d ago

Major Versions

0.1.1 → 1.22025-03-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e5f4fbc8c4421652cd449543bf6348744fd20e44163a2ac15e2777a520cc258?d=identicon)[abianbiya](/maintainers/abianbiya)

---

Top Contributors

[![abianbiya](https://avatars.githubusercontent.com/u/26533949?v=4)](https://github.com/abianbiya "abianbiya (3 commits)")

---

Tags

filehandlerabianbiya

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abianbiya-filehandler/health.svg)

```
[![Health](https://phpackages.com/badges/abianbiya-filehandler/health.svg)](https://phpackages.com/packages/abianbiya-filehandler)
```

###  Alternatives

[overtrue/laravel-filesystem-qiniu

A Qiniu storage filesystem for Laravel.

482229.7k16](/packages/overtrue-laravel-filesystem-qiniu)[rahulhaque/laravel-filepond

Use FilePond the Laravel way

261114.4k2](/packages/rahulhaque-laravel-filepond)

PHPackages © 2026

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