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:
<html> <head> <title>Upload Form</title> </head> <body> <?php echo $error;?> <?php echo form_open_multipart('upload/do_upload');?> <input type="file" name="userfile" size="20"/> <br><br> <input type="submit" value="upload"/> </form> </body> </html>
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); } } }
Next, create another file in the view. upload_success.php
<html> <head> <title>Upload Form</title> </head> <body> <h3>Your file was successfully uploaded!</h3> <ul> <?php <foreach($upload_data as $item=>$value):?> <li> <?php echo $item;?>:<?php echo $value;?> </li> <?php?> </ul> </body> </html>
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!