How to upload images using the CI framework

Source: Internet
Author: User
This article mainly introduces the CI (CodeIgniter) framework to implement image upload methods. combined with the instance form, it analyzes the related operation skills of calling the file upload class based on CodeIgniter to implement the image upload function, for more information about how to use the CI (CodeIgniter) framework to upload images, combined with examples, this article analyzes the related operation skills for calling the file upload class based on CodeIgniter to implement the image upload function. For more information, see

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:

      Upload Form          
       
             

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.

      Upload Form        Your file was successfully uploaded!    
 
 
    $value):?>
  • :

The above is a detailed description of how the CI framework uploads images. For more information, see other related articles in the first PHP community!

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.