Php implements image upload and cropping functions. php image upload class. php mobile terminal uploads images. php mobile phone uploads images.

Source: Internet
Author: User
Image upload: php allows you to upload and cut images. this example introduces the code for php to upload and cut images for your reference, the specific content is as follows. lo This article introduces the code for php to implement image upload and cut functions 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 | jp G | 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.

The above introduces the php image upload and cut functions, including image upload and php content, and hopes to help those who are interested in PHP tutorials.

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.