PHP Codeigniter Image File Upload

PHP Codeigniter Image File Upload

Today, We want to share with you PHP Codeigniter Image File Upload.
In this post we will show you How to Image and File Upload in Codeigniter, hear for Codeigniter File Upload Tutorial With PHP Code Examples we will give you demo and example for implement.
In this post, we will learn about How to Upload Image and File in CodeIgniter with an example.

upload file/image in CodeIgniter my latest post is about the CodeIgniter framework(C.I.) file or image upload.
By the use of the file uploading class in codeigniter Framework, you can easily upload a file or an image.
CodeIgniter’s framework File Uploading Class used to permits files or image to be uploaded.

Read Also:  PHP Laravel 6 Custom Error Page Example

CI – Uploading a file all involves the following list of Simple process:

here , An upload form (Using HTML form)is displayed, allowing a user to select a new file or images and upload it folder.
When the form(HTML form) is submitted (using POST Method), the file or image is uploaded to (root upload folder)the destination you specify(Like uploads directory in root).
and Along the way(other), the file or image is validated(Like jpg,png,etc..) to make sure it is (check format) allowed to be uploaded based and display message on the preferences you set(using ci).
successfully upload file or images Once uploaded, to the user will be show a success message here form.

Read Also:  Vuejs set focus Textbox Components

Following the all steps display in the given best example easy to understand the file or images uploading process(Step by step) in CodeIgniter framework.

Step By step – Creating the Upload Form using CodeIgniter Framework

Folder Path : applications/views/ci_upload_form.php.

<html>
<head>
<title>Upload Form - CodeIgniter - File Uploading</title>
</head>
<body class="well">

<?php echo $disperrorgenrate;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="22" />

<br /><br />
<p>
<input type="submit" value="upload file or Images" />
</p>
</form>

</body>
</html>

The Success Page

applications/views/upload_success.php

<html>
<head>
<title>Upload Form - CodeIgniter Image and File Upload</title>
</head>
<body class="well">

<h3>Your CodeIgniter Framework file was successfully easy way to uploaded!</h3>

<ul>
<?php foreach ($data_upload_data as $item => $value):?> // Foreach start
<li><?php echo $item;?>: <?php echo $value;?></li> //looping
<?php endforeach; ?>//End For each
</ul>

<p><?php echo anchor('upload', 'Select Upload or drag and drop Another File or images!'); ?></p>

</body>
</html>

The Controller File

Folder Path : applications/controllers/upload.php

class Upload extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
	}

	function index()
	{
		$this->load->view('ci_upload_form', array('disperrorgenrate' => ' ' ));
	}

	function do_upload()
	{
		$config['upload_path'] = './imageuploads/'; //upload images path
		$config['allowed_types'] = 'gif|jpg|png'; // file format validation
		$config['max_size']	= '142'; // images max size
		$config['max_width']  = '1250'; // images max width
		$config['max_height']  = '789'; // images max height

		$this->load->library('upload', $config);

		if ( ! $this->upload->do_upload())
		{
			$disperrorgenrate = array('disperrorgenrate' => $this->upload->display_disperrorgenrates());

			$this->load->view('ci_upload_form', $disperrorgenrate);
		}
		else
		{
			$data = array('data_upload_data' => $this->upload->data());

			$this->load->view('upload_success', $data);
		}
	}
}

Create The Upload Folder in your codeigniter framework applications

You will need a one destination (images upload folder) folder for your file or images uploaded images.new Create a folder at the root directory of your CodeIgniter framework installation applications_name called uploads and set it is the file all permissions to 777(read,write or upload).

Read Also:  Vuejs loop each Example with Demo

Excute : Try it!

Pakainfo.com/index.php/upload/


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  How to convert date format in PHP?
  2. Read Also:  jquery multiple Image Upload with preview and Delete using PHP
  3. Read Also:  How To Work With Laravel 6 Flash Messages?
  4. Read Also:  how to save ckeditor text in database php?
  5. Read Also:  Send PHP variable to bootstrap modal popup via Ajax
  6. Read Also:  Laravel Encryption Decryption using Crypt class
  7. Read Also:  Ng-Bind Directive using Angular Example
  8. Read Also:  PHP Laravel 6 Custom Error Page Example
  9. Read Also:  Laravel Encryption Decryption using Crypt class
  10. Read Also:  Send PHP variable to bootstrap modal popup via Ajax
CLOSEX