mr-chauhan/quick-file-uploader

A simple and customizable Laravel package for handling file uploads with validation, error logging, and facade support.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/mr-chauhan/quick-file-uploader

v1.0.1 2025-04-25 07:04 UTC

This package is auto-updated.

Last update: 2025-12-25 08:51:04 UTC


README

A simple and customizable Laravel package for handling file uploads with validation, error logging, and facade support.

✨ Features

  • ✅ Upload and replace files easily
  • ✅ Validate file extensions and size dynamically
  • ✅ Catch and log upload errors to a dedicated log file
  • ✅ Facade support (FileUploader) for clean and readable usage
  • ✅ Auto-creates directory if it doesn't exist
  • ✅ Seamless integration into any Laravel project

🚀 Installation

composer require mr-chauhan/quick-file-uploader

⚙️ Configuration

Step 1: Publish the configuration file (optional)

php artisan vendor:publish --tag=fileuploader-config

This will create a config file at:

config/fileuploader.php

Step 2: (Optional) Define a custom log channel in > config/logging.php

'channels' => [
    'fileuploader' => [
        'driver' => 'single',
        'path' => storage_path('logs/fileuploader.log'),
        'level' => 'info',
    ],
],

📦 Usage

Import the facade

use FileUploader;

Call the method from controller or service

$response = FileUploader::uploadAndReplaceFile(
    $existingFileName,          // null or old filename for replacement
    $request->file('document'), // instance of UploadedFile
    public_path('uploads/docs'),// destination folder path
    'document',                 // input field name
    ['pdf', 'jpg', 'docx'],     // allowed file extensions
    2048                        // max size in KB
);

Sample JSON response

{
  "success": true,
  "response": "20250425123456.pdf",
  "message": "File Uploaded Successfully"
}

On validation or error failure:

{
  "success": false,
  "response": null,
  "message": "The file size exceeds 2048KB limit."
}

📝 Logging

All file upload activities (success or error) are logged in:

storage/logs/fileuploader.log

🧠 Behind the Scenes

  • Uses Laravel's built-in File and UploadedFile classes.

  • Catches and logs exceptions using Laravel’s logging system.

  • Returns clean JSON responses to simplify frontend error handling.

🙋‍♂️ Author

Mr. Chauhan

📄 License

This package is open-sourced software licensed under the MIT license.