Home » Upload Multiple File and Image in CodeIgniter

Upload Multiple File and Image in CodeIgniter

by Online Tutorials Library

Upload Multiple File and Image in Codeigniter

In this section, we will learn how to upload more than one image and file by using Codeigniter. The following example provides a simple way to upload more than one image and file. In order to upload multiple files, we will use the upload library in Codeigniter. This library uses an uploads directory to save all the files and images. The steps to upload more than one image and files are described as follows:

Step 1:

In this step, we are going to Download Codeigniter 3. In our project, we are going to download the latest version of Codeigniter, which is 3. We can download it using the following link:

Step 2:

In the second step, we are going to Add Route. We will use our route file to add route. In our below example of image uploading, we will create route. For this, we will use a route file and add the following content in that file.

application/config/routes.php

Step 3:

In the third step, we are going to Create Controller. For this, we will create an “ImageUpload” controller. After that, we will create two functions index() and uploadImage(). We will use the application/controllers/Items.php path so that we can create the Items.php file. After creating this file, we will add the following code into it:

application/controllers/ImageUpload.php

Step 4:

In the fourth step, we are going to Create View. For our example, we will create a view file imageUploadForm.php. We will use helper and url helper in this file so that we can write html form design. Now we will update the following file:

application/views/imageUploadForm.php:

Now our above code is ready to run. In order to run this code, we need to create a “Upload” folder. We will create it in our root directory. The “upload” directory will get all the uploaded images. That’s why we should also require permission.

Now we will use our root directory and run the command, which is described as follows:

Now we will use our browser and open the URL, which is described as follows:

Firstly, we will open the following configuration file and then set base URL on that file like this:

application/config/config.php

After running the above code, we are going to have the following output:

Upload Multiple File and Image in Codeigniter


You may also like