How to use the CodeIgniter framework to implement image uploading

不言
Release: 2023-04-01 07:34:01
Original
1323 people have browsed it

This article mainly introduces the CI (CodeIgniter) framework to implement image uploading methods, and analyzes the relevant operating techniques based on CodeIgniter calling the file upload class to implement the image uploading function in the form of examples. Friends in need can refer to it

The example in this article describes how the CodeIgniter framework implements image uploading. I share it with you for your reference, as follows:

Regarding the commonplace issue of image uploading, I have to repeat it again, because after all, there are some things about this framework that are worth learning and learning from. This article I wrote it with the help of official documents, but some places still need to be marked.

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

  Upload Form 


Copy after login

Codeigniter has its own very rich upload Class library, let’s take a look at the controller. There is an Upload.php file in the Controller. 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); } } }
Copy after login

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

  Upload Form 

Your file was successfully uploaded!

    $value):?>
  • :
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. Please pay attention to more related content. PHP Chinese website!

Related recommendations:

About common image processing methods encapsulated in CI framework

About loading views in CI framework views Method

Summary of common functions for CI framework AR database operations

The above is the detailed content of How to use the CodeIgniter framework to implement image uploading. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!