PHPackages                             sanil/fileupload - 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. sanil/fileupload

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

sanil/fileupload
================

A Laravel file upload helper with image resizing support

v1.0.6(11mo ago)053MITPHPPHP ^8.1

Since Apr 23Pushed 11mo ago1 watchersCompare

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

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

Laravel File Upload Trait
=========================

[](#laravel-file-upload-trait)

[![Packagist](https://camo.githubusercontent.com/5a009b18fbaafa18642fa8be59ca1e9bd770e385054e84ef6f0b3bd2d7c7da3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616e696c2f66696c6575706c6f61642e737667)](https://packagist.org/packages/sanil/fileupload)[![PHP Version Support](https://camo.githubusercontent.com/4cb72f9d37be38e84d8e987852c0bb20bb124de2b896c9ff2f47de0de63faf88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616e696c2f66696c6575706c6f61642e737667)](https://www.php.net/)

A Laravel package to handle file uploads, including image resizing, storage management, and URL generation for uploaded files. This package provides a reusable solution for managing file uploads in Laravel applications with support for multiple storage disks, collections, and image resizing using the Spatie Image library.

Features
--------

[](#features)

- **File Uploads**: Upload files to specified storage disks with unique directory paths using UUIDs.
- **Image Resizing**: Automatically resize images to predefined sizes (configured in config file).
- **Storage Management**: Handle file storage, visibility, and directory creation on various disks (e.g., public, S3).
- **URL Generation**: Generate public or temporary URLs for uploaded files, with support for regenerating missing thumbnails.
- **File Deletion**: Delete individual or all uploads associated with a model, including their storage directories and database records.
- **Error Logging**: Comprehensive error logging for upload, resize, and deletion operations.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 10.x

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

[](#installation)

1. **Install the Package**

    You can install this via Composer:

    ```
    composer require sanil/fileupload

    ```

    Publish and run migrations:

    ```
    php artisan vendor:publish --tag=fileupload-migrations
    php artisan migrate

    ```

    Publish config files (optional):

    ```
    php artisan vendor:publish --tag=fileupload-config

    ```
2. **Configure Image Sizes**

    Add image size configurations to your config/image.php file:

    ```
    return [
        'size' => [
            [300, 300], // Thumbnail size (width, height)
            [800, 600], // Medium size
            [1200, 900], // Large size
        ],
    ];

    ```

Usage
-----

[](#usage)

1. **Add the Trait to a Model**

    Use the FileUpload trait in any model that needs file upload functionality:

    ```
    namespace App\Models;

    use Illuminate\Database\Eloquent\Model;
    use Sanil\FileUpload\Traits\FileUpload;

    class Post extends Model
    {
        use FileUpload;
    }

    ```
2. **Upload a File**

    Upload a file (e.g., from a controller):

    ```
    use App\Models\Post;
    use Illuminate\Http\Request;

    public function uploadFile(Request $request)
    {
        $post = Post::find(1);
        $file = $request->file('file');

        $upload = $post->upload($file, 'images', 'public');

        if ($upload) {
            return response()->json(['message' => 'File uploaded successfully', 'upload' => $upload]);
        }

        return response()->json(['message' => 'File upload failed'], 500);
    }

    ```
3. **Get File URL**

    Generate a public or temporary URL for an uploaded file:

    php

    ```
    $post = Post::find(1);
    $upload = $post->uploads()->first();

    // Get URL for the full-size image
    $fullUrl = $post->get_file_public_url($upload, 'full');

    // Get URL for a resized image (e.g., 300x300)
    $thumbnailUrl = $post->get_file_public_url($upload, '300x300');

    ```
4. **Delete Uploads**

    Delete a specific upload or all uploads for a model:

    php

    ```
    $post = Post::find(1);

    // Delete a specific upload
    $upload = $post->uploads()->first();
    $post->deleteUploads($upload);

    // Delete all uploads
    $post->deleteUploads();

    ```

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

[](#configuration)

- **Image Sizes**: Define in config/image.php as an array of width, height pairs.
- **Visibility**: The trait respects the disk's visibility setting (public or private) and applies it to uploaded files and thumbnails.

Error Handling
--------------

[](#error-handling)

- Errors during upload, resizing, or deletion are logged using Laravel's Log facade.
- Methods return false on failure, with detailed error messages in the logs.

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

[](#contributing)

1. Fork the repository.
2. Create a feature branch (git checkout -b feature/new-feature).
3. Commit your changes (git commit -m 'Add new feature').
4. Push to the branch (git push origin feature/new-feature).
5. Open a pull request.

License
-------

[](#license)

This project is licensed under the MIT License. See the LICENSE file for details.

Support
-------

[](#support)

For issues, questions, or suggestions, please open an issue on the GitHub repository or contact the maintainer at:

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance53

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~12 days

Total

6

Last Release

330d ago

### Community

Maintainers

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

---

Top Contributors

[![sonill](https://avatars.githubusercontent.com/u/421800?v=4)](https://github.com/sonill "sonill (15 commits)")

---

Tags

filelaravelupload

### Embed Badge

![Health badge](/badges/sanil-fileupload/health.svg)

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

###  Alternatives

[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)[illuminate/filesystem

The Illuminate Filesystem package.

15161.6M2.6k](/packages/illuminate-filesystem)[stechstudio/laravel-zipstream

A fast and simple streaming zip file downloader for Laravel.

4633.7M3](/packages/stechstudio-laravel-zipstream)[spatie/laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel

2408.9M13](/packages/spatie-laravel-google-cloud-storage)[azure-oss/storage-blob-laravel

Azure Storage Blob filesystem driver for Laravel

63582.2k1](/packages/azure-oss-storage-blob-laravel)[spatie/laravel-backup-server

Backup multiple applications

17016.7k1](/packages/spatie-laravel-backup-server)

PHPackages © 2026

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