PHP code example of craigh / laravel-file-uploader

1. Go to this page and download the library: Download craigh/laravel-file-uploader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

craigh / laravel-file-uploader example snippets


Upload::file($request->all())
->createDirs(true)
->maxFileSize(5,'MB')
->allowedMimeTypes(['image/jpeg', 'image/png', 'image/gif'])
->move();

protected $uploadDir; // Upload directory
protected $allowedMimeTypes = []; // Only allow these file to be uploaded
protected $blockedMimeTypes = []; // Don't allow these files to be uploaded
protected $maxFileSize = 1000000; // In bytes
protected $makeFilenameUnique = false; // Make the filename unique if two files have the same name
protected $overwrite = false; // Allow overwriting of files with the same name
protected $createDirs = false; // Allow the automatic creation of any upload directories

use Humps\LaravelFileUploader\LaravelFileUploader;

class ImageUploader extends LaravelFileUploader{
    
   protected $uploadDir = 'images/';
   protected $maxFileSize = 5+6e; // 5 MB
   protected $createDirs = true;
   protected $makeFilenameUnique = true;
   
   protected $allowedMimeTypes = [
    'image/jpeg',
    'image/png',
    'image/gif'
   ];
  
}

/**
 * Example using dependency injection
 **/
private $upload;

function __construct(ImageUploader $upload){
    $this->upload = $upload;
}

public function store(Request $request){
    $this->upload->file($request->file('file'))->move();
}

$uploadExceptionHandler = app()->make('uploadExceptionHandler', [$e]);
if ($errors = $uploadExceptionHandler->getUploadErrors()) {
  return $errors;
}

use Humps\LaravelFileUploader\LaravelFileUploaderExceptionHandler as BaseHandler;

class CustomUploadExceptionHandler extends BaseHandler {
  protected function response(){
    die($this->error);
  }
}


use Humps\FileUploader\Uploader;

private $upload;

function __construct(Uploader $upload){
    $this->upload = $upload;
}