The CI (CodeIgniter) framework implements the Image Upload method, cicodeigniter

Source: Internet
Author: User
Tags codeigniter

The CI (CodeIgniter) framework implements the Image Upload method, cicodeigniter

This document describes how to upload images using the CodeIgniter framework. We will share this with you for your reference. The details are as follows:

I have to repeat the conventional problem of uploading images once again, because the framework is worth learning and learning for some places. I wrote this article using official documents, however, in some cases, you need to mark it.

Next let's take a look at uploading images. First, create a View File text. php In the "./application/views/" folder. The Code is as follows:

Codeigniter has its own rich upload class library. Let's take a look at the Controller. In the Controller, an Upload. php file, the Code is as follows:

class Upload extends CI_Controller{  public function __construct(){    parent::__construct();    $this->load->helper("form","url");  }  public function index(){    $this->load->view('test',array("error"=>''));  }  public function do_upload(){    $config['upload_path']='./uploads/';    $config['allowed_types']='gif|jpg|png';    $config['max_size']=100;    $config['max_width']=1024;    $config['max_height']=768;    $this->load->library('upload',$config);    if(!$this->upload->do_upload('userfile')){      $error=array('error'=>$this->upload->display_errors());      $this->load->view('test',$error);    }else{      $data=array('upload_data'=>$this->upload->data());      $this->load->view('upload_success',$data);    }  }}

Next, create another file upload_success.php in the view.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.