Laravel – Multiple Images Uploading using dropzone.js Example

Laravel – Multiple Images Uploading using dropzone.js Example

In this post we will give you information about Laravel – Multiple Images Uploading using dropzone.js Example. Hear we will give you detail about Laravel – Multiple Images Uploading using dropzone.js ExampleAnd how to use it also give you demo for it if it is necessary.

We always have to do image uploading in our laravel application, In this post i give you example code of how to upload multiple images using dropzone.js. dropzone.js through we can make image uploading very simply and with best layout.

Dropzone.js is a jquery plugin, dropzone.js through we can select one by one image and also with preview. After choose image from browse we can see preview of image. dropzone.js also provide filter like we can make validation for max upload, specific image or file extension etc.

In this example i create two route, one for display view and another for store image. i also create two method on HomeController and one blade file with dropzone js plugin js and css that way we can display layout. You can implement in your laravel application by following few step.

After run success this example you will find bellow preview in your application.

Preview:

Step 1: Add Route

In first step, we will add two new route one for display view and another for store image in our routes.php file. So, open your route file and add bellow two new routes.

app/Http/routes.php

Route::get('dropzone', 'HomeController@dropzone');

Route::post('dropzone/store', ['as'=>'dropzone.store','uses'=>'HomeController@dropzoneStore']);


Step 2: Add Controller Method

In this step we will add two method on HomeController that way we can handle two route with image upload code. So, if you haven’t created HomeController then create new as bellow, or add two method.

You have to also create new images folder in your public folder for store image.

app/Http/Controllers/HomeController.php

namespace AppHttpControllers;


use AppHttpRequests;

use IlluminateHttpRequest;


class HomeController extends Controller

{


/**

* Generate Image upload View

*

* @return void

*/

public function dropzone()

{

return view('dropzone-view');

}


/**

* Image Upload Code

*

* @return void

*/

public function dropzoneStore(Request $request)

{

$image = $request->file('file');

$imageName = time().$image->getClientOriginalName();

$image->move(public_path('images'),$imageName);

return response()->json(['success'=>$imageName]);

}


}

Step 3: Add Blade File

At last step we have to create dropzone-view.blade.php file in your resources directory. in this file i write code of image uploading using dropzone.js, so let’s create new blade file and put bellow code:

resources/views/dropzone-view.blade.php

<!DOCTYPE html>

<html>

<head>

<title>Upload Multiple Images using dropzone.js and Laravel</title>

<script src="http://demo.onlinecode/plugin/jquery.js"></script>

<link rel="stylesheet" href="http://demo.onlinecode/plugin/bootstrap-3.min.css">

<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/min/dropzone.min.css" rel="stylesheet">

<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.js"></script>

</head>

<body>


<div >

<div >

<div >

<h1>Upload Multiple Images using dropzone.js and Laravel</h1>

{!! Form::open([ 'route' => [ 'dropzone.store' ], 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone', 'id' => 'image-upload' ]) !!}

<div>

<h3>Upload Multiple Image By Click On Box</h3>

</div>

{!! Form::close() !!}

</div>

</div>

</div>


<script type="text/javascript">

Dropzone.options.imageUpload = {

maxFilesize : 1,

acceptedFiles: ".jpeg,.jpg,.png,.gif"

};

</script>


</body>

</html>

If you found “Form Class not found error” then you can solve from this link : HTML/FORM not found in Laravel 5?.

You can get more information about Dropzone.js from here : Click Here.

Hope this code and post will helped you for implement Laravel – Multiple Images Uploading using dropzone.js Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

9  +  1  =  

We accept paid advance and paid guest Posting on our Site : Contact US