PHP based on codeigniter implementation of image upload, clipping function, _php tutorial

Source: Internet
Author: User
Tags learn php learn php programming codeigniter

PHP based on codeigniter implementation of image upload, clipping function,


This example for everyone to share the CodeIgniter picture upload, cut, controller class, for your reference, the specific content as follows

<?phpdefined (' BasePath ') or exit (' No Direct script access allowed '); class Index extends My_controller {function __cons    Truct () {parent::__construct ();  $this->load->helper (Array (' form ', ' url '));  }/** * Home */Public Function index () {$this->load->view (' Upload_form ', Array (' ERROR ' = ') ');    } public Function Do_upload () {$config [' upload_path '] = './data/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_err      ORS ());    $this->load->view (' Upload_form ', $error);            } else {$data = array (' upload_data ' = = $this->upload->data ());         $this->load->library (' image_lib '); List ($width, $height) = getimagesize ($data [' Upload_data '[' Full_path ']);   $config [' image_library '] = ' gd2 ';   $config [' source_image '] = $data [' upload_data '] [' full_path '];   $config [' maintain_ratio '] = TRUE;   if ($width >= $height) {$config [' master_dim '] = ' height ';   }else{$config [' master_dim '] = ' width ';   } $config [' width '] = 180;   $config [' height '] = 180;   $this->image_lib->initialize ($config);    $this->image_lib->resize ();   $config [' maintain_ratio '] = FALSE;   if ($width >= $height) {$config [' x_axis '] = Floor (($width * 180/$height-180)/2);   }else{$config [' y_axis '] = Floor (($height * 180/$width-180)/2);   } $this->image_lib->initialize ($config);         $this->image_lib->crop ();    $this->load->view (' upload_success ', $data); }  }}

The above is the whole content of this article, I hope that you learn PHP programming help.

http://www.bkjia.com/PHPjc/1127901.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127901.html techarticle PHP based on codeigniter implementation of image upload, clipping function, this example for everyone to share the CodeIgniter picture upload, cut, controller class, for your reference, the specific content as follows Phpde ...

  • 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.