Codeigniter 3 upload multiple images using drag and drop with example

Codeigniter 3 upload multiple images using drag and drop with example

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') OR exit('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') OR exit('No direct script access allowed');

class ImageController extends CI_Controller {

	public function index()
	{
		$this->load->view('dropzone_template');
	}


	public function uploadImage()
	{
		$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>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.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 class="container">
	<div class="row">
		<div class="col-md-12">
			<form a ction="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>

Phone: (+91) 8800417876
Noida, 201301
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
porno izle
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat
sohbet okey oyna
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort