Upload file in laravel


Select image to upload:

#disable CSRF token @Kernel.php

use Illuminate\Support\Facades\Input;

aliases array as below config\app.php

‘Input’ => Illuminate\Support\Facades\Input::class,


Route::post(‘upload’, function(){
$avarta = Input::file(‘fileToUpload’);
if(strpos($avarta->getClientMimeType(),’image’) !== FALSE){

$upload_folder = ‘/assets/uploads/’;

$file_name = str_random(). ‘.’ . $avarta->getClientOriginalExtension();

$avarta->move(public_path() . $upload_folder, $file_name);

echo URL::asset($upload_folder . $file_name); // get upload file url

return Response::make(‘Success’, 200);
return Response::make(‘Avatar must be image’, 400); // bad request

Leave a Reply

Your email address will not be published. Required fields are marked *