PHPackages                             bkstar123/laravel-uploader - 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. bkstar123/laravel-uploader

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

bkstar123/laravel-uploader
==========================

A Laravel package for handling file upload

1.0.14(5y ago)797141MITPHPPHP ^7.1.3

Since Jun 16Pushed 5y agoCompare

[ Source](https://github.com/bkstar123/laravel-uploader)[ Packagist](https://packagist.org/packages/bkstar123/laravel-uploader)[ RSS](/packages/bkstar123-laravel-uploader/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (17)Used By (1)

laravel-uploader
================

[](#laravel-uploader)

> Provide a Laravel backend for handling file upload

1.Requirements
--------------

[](#1requirements)

It is recommended to install this package with PHP version 7.1.3+ and Laravel Framework version 5.5+

2.Installation
--------------

[](#2installation)

```
composer require bkstar123/laravel-uploader

```

You can upload files to the backend either via a normal form submit or via AJAX calls (built by yourself or any third party plugins).

**Note**:

- Form submit supports only single file upload. For multiple files upload, you should use AJAX to send files in parallel requests
- The package also includes a frontend fileinput plugin from Krajee for quickly demonstrating the AJAX uploading. The assets included in the package are barely minimum and may not be up to date. You should consult  for the latest version and more advanced use cases of the plugin
- The Krajee plugin's full version can be installed via `npm install bootstrap-fileinput`
- In order to use the included frontend assets, run `php artisan vendor:publish --tag=bkstar123_fileupload.assets`

3.Usage
-------

[](#3usage)

### 3.1 In Controller

[](#31-in-controller)

Firstly, you typehint `Bkstar123\LaravelUploader\Contracts\FileUpload` in a controller constructor to inject a FileUpload service.

```
use Bkstar123\LaravelUploader\Contracts\FileUpload;
-----------------
protected $fileupload;

public function __construct(FileUpload $fileupload)
{
    $this->fileupload = $fileupload;
}
```

Then, in the method which is supposed to handle a file upload request, you call

```
$this->fileupload->handle(Request $request, string $fieldname, array $uploadSettings)
```

Where:

- **$request**: full Laravel request object
- **$fieldname**: name of the file input field in your frontend
- **$uploadSettings** (optional): inline settings to customize the behavior of the backend

**$uploadSettings** is an asociative array with the following possible keys:

- `directory`: the root directory containing your uploaded files
- `disk`: the storage disk for file upload. Check Laravel official documentation for more details, e.g: `public`, `s3`
- `maxFileSize` (in bytes): the maximum size of an uploaded file that can be accepted by the backend
- `allowedExtensions`: array of acceptable file extensions, e.g: `['jpg', 'png', 'pdf']`

The backend default settings are as follows:

```
- 'directory': 'media'
- 'disk': 'public'
- 'maxFileSize':  50 MB
- 'allowedExtensions': 'png','jpg','jpeg','mp4','doc','docx','ppt','pptx','xls','xlsx','txt','pdf'

```

You can change these default settings by using the following environment variables in .env:

- `BKSTAR123_LARAVEL_UPLOADER_DEFAULT_DISK`
- `BKSTAR123_LARAVEL_UPLOADER_DEFAULT_DIRECTORY`
- `BKSTAR123_LARAVEL_UPLOADER_DEFAULT_MAX_FILE_SIZE` (in bytes)

**Note**: The inline settings will overwrite the default ones

If the upload succeeds,`$this->fileupload->handle(Request $request, string $fieldname, array $uploadSettings)` will return the following data for being further persisted to database:

```
[
    'filename' => 'the original file name',
    'path' => 'path to file location relative to the disk storage',
    'url' => 'public url to access the file in browser',
    'disk' => 'name of storage disk'
]
```

If the uploaded file is not valid, then `false` will be returned and an error message will be set for `$this->fileupload->uploadError`

### 3.2 In frontend view

[](#32-in-frontend-view)

#### 3.2.1 Normal form upload

[](#321-normal-form-upload)

(Only support single file upload)

**Example**:

```

    @csrf()

```

#### 3.2.2 AJAX uploading using default frontend assets from Krajee

[](#322-ajax-uploading-using-default-frontend-assets-from-krajee)

(Support sending multiple files in parallel requests)

**Example**:

```
>

    File Upload

    $(document).ready(function(){
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $("#photo").fileinput(
            {
                uploadUrl: '/upload',
                maxFileCount: 5,
                maxFileSize: 10420, //in KBs
                allowedFileExtensions: ['jpg', 'png', 'pdf'],
                previewFileType:'any',
                showUpload: false
            }
        ).on("filebatchselected", function(event, files) {
            $("#photo").fileinput("upload");
        });
    });

```

**Note**: When using Krajee fileinput plugin, you must return a json response from the controller method which handles the upload request as follows:

```
if ($path = $this->fileupload->handle($request, 'photo', $uploadSettings)) {
    // Persist $path data to database
    return json_encode([]);
}

return json_encode([
    'error' => $this->fileupload->uploadError
]);
```

#### 3.2.3 AJAX uploading using @bkstar18/jquery-ajax-uploader plugin (***written by myself***)

[](#323-ajax-uploading-using-bkstar18jquery-ajax-uploader-plugin-written-by-myself)

You can check its full documentation at

**Example use**:

***a) Installation***

- `npm install --save-dev @bkstar18/jquery-ajax-uploader`
- In `resources/js/bootstrap.js`, place the following line:

```
try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
    require('@bkstar18/jquery-ajax-uploader'); // Add this line
} catch (e) {}
```

- Then, compile your assets using `laravel-mix`: `npm run production`
- Alternatively, if you do not want to bundle this plugin into the main app.js, you can place the following line in `webpack.mix.js`:

```
mix.js('resources/js/app.js', 'public/js')
   .copy('node_modules/@bkstar18/jquery-ajax-uploader/dist/bkstar123-ajax-uploader.min.js', 'public/js/bkstar123-ajax-uploader.min.js') // Add this line
   .sass('resources/sass/app.scss', 'public/css');
```

Then, include `` in any view where you want to use the plugin. Remember to load JQuery before using the plugin.

***b) In HTML section***

```

    Upload Images

```

***c) In Javascript section***

```
$(document).ready(function () {
    $('#image-upload').bkstar123_ajaxuploader({
        allowedExtensions: ['png','jpg','jpeg'],
        batchSize: 5,
        outerClass: 'col-md-12',
        uploadUrl: '/api/upload',
        beforeSend: (xhr) => {
            xhr.setRequestHeader('X-AUTHOR', 'TUANHA');
        },
        onResponse: (response) => {
            let res = JSON.parse(response)
            $('#gallery').append(``);
        }
    });
});
```

***d) In Laravel Controller method***

```
public function upload(Request $request, FileUpload $fileupload)
{
    $data = $fileupload->handle($request, 'image', ['allowedExtensions' => ['jpg', 'png', 'jpeg']]);
    if (!$data) {
        return response()->json(['error' => $fileupload->uploadError], 422);
    }
    // Saving data to database
    return response()->json(['success' => "{$data['filename']} has been successfully uploaded", 'data' => $data], 200);
}
```

**Note**:
You should make sure that the page html layout has the following `` tag:

```

```

Otherwise, the request may be blocked by Laravel by default. See more details at .

The plugin automatically checks the existence of this `` tag, get its content and associate `X-CSRF-TOKEN` header with the uploading request.

Alternatively, ***if and only if*** this `` tag does not exist (maybe you do not want to use, or for somewhat reasons), then you can include `X-CSRF-TOKEN` request header before sending files to server via `beforeSend(xhr)` hook as follows:

```
$(document).ready(function () {
    $('#image-upload').bkstar123_ajaxuploader({
        ...
        beforeSend: (xhr) => {
            xhr.setRequestHeader('X-CSRF-TOKEN', {!! json_encode(csrf_token()) !!});
        },
        ...
    });
});
```

#### 3.2.4 AJAX uploading using @bkstar18/vue-ajax-uploader plugin (***written by myself***)

[](#324-ajax-uploading-using-bkstar18vue-ajax-uploader-plugin-written-by-myself)

Check  for details.

### 3.3 Physically remove an uploaded file

[](#33-physically-remove-an-uploaded-file)

You can physically delete an uploaded file as in following example:

```
$this->fileupload->delete($photo->disk, $photo->path)
```

In this example, the **photos** table must have `disk` and `path` columns to persist a `photo` instance.

You should physically remove an uploaded file only after deleting its relevant record in the database.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% 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 ~37 days

Recently: every ~117 days

Total

15

Last Release

1998d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/90147e91656dcac27be0a14b7600445eae40a5a8f3859f8ac9e1f9a051626095?d=identicon)[bkstar123](/maintainers/bkstar123)

---

Top Contributors

[![bkstar123](https://avatars.githubusercontent.com/u/12879662?v=4)](https://github.com/bkstar123 "bkstar123 (25 commits)")[![opaweb](https://avatars.githubusercontent.com/u/43017037?v=4)](https://github.com/opaweb "opaweb (1 commits)")

---

Tags

backendfileuploadfileuploaderlaravellaravel-uploaderuploaduploaderlaravelfile-upload

### Embed Badge

![Health badge](/badges/bkstar123-laravel-uploader/health.svg)

```
[![Health](https://phpackages.com/badges/bkstar123-laravel-uploader/health.svg)](https://phpackages.com/packages/bkstar123-laravel-uploader)
```

###  Alternatives

[kingofcode/laravel-uploadable

Laravel Uploadable trait to automatically upload images and files with minimum configuration

286.4k](/packages/kingofcode-laravel-uploadable)[josefbehr/filament-spatie-media-library-croppie

A filament form field for image upload using spatie media library and croppie.js

126.6k](/packages/josefbehr-filament-spatie-media-library-croppie)[fojuth/plupload

A Laravel 4 implementation of Plupload (http://www.plupload.com/).

162.5k](/packages/fojuth-plupload)[menthe/aliyun-ueditor

UEditor for laravel5 and Aliyun OSS.Store all images and files in Aliyun OSS. Support i18n. UEditor is a Rich Text Web Editor From Baidu.

172.4k](/packages/menthe-aliyun-ueditor)

PHPackages © 2026

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