Codeigniter 3 upload multiple images using drag and drop with example
In this post we will give you information about Codeigniter 3 upload multiple images using drag and drop with example. Hear we will give you detail about Codeigniter 3 upload multiple images using drag and drop with exampleAnd how to use it also give you demo for it if it is necessary.
Codeigniter upload multiple images using drag and drop with example
In this example, I am going to tell you how to upload multiple image using dropzone library in Codeigniter application. You can drag and drop image to upload image on the server.
With the help of dropzone plugin, you can easily upload images on the server.
In most of the web application, it requires to upload bulk images with preview feature.
In HTML, there is a default feature with file type of input field with multiple but it does not look so much pretty as dropzone provides.
You can freely download the dropzone library because it is an open source javascript library.
Dropzone provides the different type of validation rules like max file upload, upload specific type of file like you can set the validation rule to take only jpeg extension.
For this example, I need to create a simple html form with the class name “dropzone” to use dropzone features and create a uploads directory to save all images.
Step 1: Download Codeigniter 3
In this first step, I need to download fresh version of Codeigniter to start with scratch.
Step 2: Add Routes
In this step, I will add two routes in my route file to handle the request to upload file on the server.
application/config/routes.php
<?php defined('BASEPATH') ORexit('No direct script access allowed'); $route['default_controller'] ='welcome'; $route['404_override'] =''; $route['translate_uri_dashes'] =FALSE; $route['dropzone-upload-image'] ='ImageController'; $route['dropzone-upload-image/post']['post'] ='ImageController/uploadImage';
Step 3: Create Image Controller
In this step, I will create a controller “ImageController.php” in following path application/controllers/.
<?php defined('BASEPATH') ORexit('No direct script access allowed'); classImageControllerextends CI_Controller { publicfunctionindex() { $this->load->view('dropzone_template'); } publicfunctionuploadImage() { $config['upload_path'] ='./uploads/'; $config['allowed_types'] ='gif|jpg|png'; $config['max_size'] =1024; $this->load->library('upload', $config); $this->upload->do_upload('file'); print_r('Image Uploaded Successfully.'); exit; } }
Step 4: Create View Files “dropzone_template.php”
In this step, I will create a view file “dropzone_template.php” to render the HTML form to upload image.
application/views/dropzone_template.php
<!DOCTYPE html> <html> <head> <title>Codeigniter - Upload multiple images using dropzone.js</title> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <linkhref="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> <divclass="container"> <divclass="row"> <divclass="col-md-12"> <formaction="dropzone-upload-image/post"enctype="multipart/form-data"class="dropzone"id="image-upload"method="POST"> <div> <center><h3>Click here to upload multiple image</h3></center> </div> </form> </div> </div> </div> <script type="text/javascript"> Dropzone.options.imageUpload = { maxFilesize:1, acceptedFiles:".jpeg,.jpg,.png,.gif" }; </script> </body> </html>
PHP : Upload multiple file using dropzone.js with drag and drop features
Hope this code and post will helped you for implement Codeigniter 3 upload multiple images using drag and drop with 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