Php implements Image Upload and cropping Based on CodeIgniter _ php instance

Source: Internet
Author: User
Tags learn php learn php programming
This article mainly introduces in detail php's function of uploading and cutting Images Based on CodeIgniter, which is of reference value, if you are interested, you can refer to the examples in this article to share with you the codeigniter image uploading, cropping, and controller classes for your reference. The specific content is as follows:

<? Phpdefined ('basepath') OR exit ('no direct script access allowed'); class Index extends MY_Controller {function _ construct () {parent :__ construct (); $ this-> load-> helper (array ('form', 'url');}/*** homepage */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_errors ()); $ 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 all the content of this article. I hope it will help you learn php programming.

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.