How to use CodeIgniter framework to implement image uploading method

Source: Internet
Author: User
Tags codeigniter
This article mainly introduced the CI (codeigniter) framework implementation of the image upload method, combined with the example form analysis based on the CodeIgniter call file upload class implementation of the image upload function related operation skills, the need for friends can refer to the next

In this paper, we describe the method of CodeIgniter framework to implement picture uploading. Share to everyone for your reference, as follows:

For the picture upload this cliché problem, I have to repeat this once again, because for this framework after all, some places worth their own learning and reference, this article I use the official documents to write, but some places need to be marked.

Let's take a look at the image upload. First create a view file in the "./application/views/" folder: text.php, the code is as follows:


CodeIgniter has its own very rich upload class library, below we take a look at the controller, a upload.php file in the controllers, 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 in the view upload_success.php


The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.