A Laravel library to provide file upload utilities. A Javascript library builds a complete file upload widget with upload button, drag-and-drop zone, progress bar and result builder. A controller is available to manage uploaded files. Current version: 3.0.4. Project on GitHub. Project on Packagist. This demosite sources available here.

On this site, you can only upload files up to 1MB and having extensions png,jpg,jpeg,gif,txt. Files will be destroyed after 10 minutes.

Upload functions

Package contains utilities that help define file upload functions quickly. It uses Laravel file storages and form validator.

File upload request

Seblhaire\Uploader\FileuploadRequest is a Laravel form Request that contain form validation rules that can be used to validate values returned by our file upload component, namely file size and file type. Use it as follows:

public function index(FileuploadRequest $request){ // process uploaded file
    $validated = $request->validated();


Seblhaire\Uploader\UploaderTrait is a trait that can be used by your file upload controller.

  • buildFileObj($filename) builds an object which contains file name and file extension.
  • buildUniqueFileName($disk, $path, $fileobj, $separator = '-') verifies if a file already exists in destination path and builds an unique filename.
  • cleanFileName($filename) removes accentuated characters and white spaces from file name.
  • getPath($request) returns a string that contains file path defined from default config files or from uploader parameters.
  • getDisk($request, $path) returns storage name either from default config file or from uploder parameters; if needed, it creates destination directory from path.
Upload controller

Here is a file upload controller that you can use as is or adapt to your needs.

class FileUploadController extends Controller
  use UploaderTrait; //provides functions to help interact with Uploader objects

  public function index(FileuploadRequest $request){ // process uploaded file
      $validated = $request->validated();
      // define storage and path parameters
      $path = $this->getPath($request);
      $disk = $this->getDisk($request, $path);
      $files = [];
      // process files
      foreach ($request->file('file') as $file){
        if (!$file->isValid()) { // file upload failed
            'ok' => false,
            'message' => 'invalid file ' . $file->getClientOriginalName()
        // gets object with file info
        $fileobj = $this->buildFileObj($this->cleanFileName($file->getClientOriginalName()));
        // if a file pattern has been set to replace original filename, build
        // another file object
        if ($request->has('filepattern') && strlen($request->input('filepattern')) > 0){
          $patternobj = $this->buildFileObj($request->input('filepattern'));
          $patternobj = null;
        if (!is_null($patternobj)){
          $destfile = $patternobj;
          if ($patternobj->ext == ''){
            $destfile->ext = $fileobj->ext;
          $destfile = $fileobj;
        // if file can't be overwitten, build unique file name
        if (!$request->input('overwrite')){
            $filename = $this->buildUniqueFileName($disk, $path, $destfile);
        }else{ // file cam be overwritten
            $filename = $destfile->name . '.' . $destfile->ext;
        // store file in destination directoty
        $filepath = $file->storeAs($path, $filename, $disk);
        $files[] = [
          'filename' => $filename,
          'ext' => $fileobj->ext,
          'mimetype' => $file->getMimeType(),
          'size' =>  $file->getSize()
        // Here you could store file info in a database table.
      return response()->json([
        'ok' => true,
        'filepath' => $path,
        'disk' => $disk,
        'baseurl' => !is_null(config('filesystems.disks.' . $disk . '.url')) ?
            (config('filesystems.disks.' . $disk . '.url') . $path) : '',
        'files' => $files,
        // other parameters you need can be