CI framework file upload and image processing Usage Analysis, ci File Upload

Source: Internet
Author: User

CI framework file upload and image processing Usage Analysis, ci File Upload

This document describes the CI framework file upload and image processing usage. We will share this with you for your reference. The details are as follows:

// List page banner image public function edit_list_page_banner ($ category_id = "") {$ category_id = empty ($ category_id )? $ _ POST ["category_id"]: $ category_id; // upload an image if (isset ($ _ POST ["key"]) & $ _ POST ["key"] = "upload") {/* 1. set_upload_path */$ config ['upload _ path'] = ". /upload/source /". date ("Y/m/d"); // if (! File_exists (". /upload/source /". date ("Y/m/d") {mkdir (". /upload/source /". date ("Y/m/d"), 0777, true); // source image path} if (! File_exists (". /upload/big_thumb /". date ("Y/m/d") {mkdir (". /upload/big_thumb /". date ("Y/m/d"), 0777, true); // large thumbnail path} if (! File_exists (". /upload/small_thumb /". date ("Y/m/d") {mkdir (". /upload/small_thumb /". date ("Y/m/d"), 0777, true ); // small thumbnail path} $ config ['allowed _ types '] = "gif | jpg | png | txt "; // file type $ config ['max _ size'] = "20000"; // maximum upload size $ this-> load-> library ("upload", $ config ); if ($ this-> upload-> do_upload ('userfile') // name = "userfile" in the form {// After the upload is successful, generate two thumbnails $ data = $ this-> upload-> data (); // return the information of the uploaded image $ this-> load-> library ("image_lib "); // load the image processing class library // The first method: Large thumbnail Configuration Parameter/* $ config_big_thumb ['image _ library'] = 'gd2 '; // gd2 Gallery $ config_big_thumb ['source _ image'] = $ data ['full _ path']; // source image $ config_big_thumb ['new _ image'] = ". /upload/big_thumb /". date ("Y/m/d "). "/". $ data ['file _ name']; // large thumbnail $ config_big_thumb ['create _ thumb'] = true; // create a thumbnail $ config_big_thumb ['maintain _ ratio '] = true; $ config_big_thumb ['width'] = 300; // width of the thumbnail $ config_big_thumb ['height'] = 300; // height of the thumbnail $ config_big_thumb ['thumb _ marker'] = "_ 300_300 "; // Add "_ 300_300" after the thumbnail name to indicate a 300*300 thumbnail * // The second one: configuration parameters for large thumbnails/* $ config_big_thumb = array ('image _ library' => 'gd2 ', // gd2 gallery 'source _ image' => $ data ['full _ path'], // source image 'new _ image' => ". /upload/big_thumb /". date ("Y/m/d "). "/". $ data ['file _ name'], // large thumbnail 'create _ thumb' => true, // whether to create a thumbnail 'maintain _ ratio '=> true, 'width' => 300, // The width of the thumbnail 'height' => 300, // The height of the thumbnail 'thumb _ marker' => "_ 300_300" // Add "_ 300_300" after the thumbnail name to indicate a 300*300 thumbnail ); * // method 3: add some configuration information to config. $ config_big_thumb = $ this-> config-> item ("config_big_thumb"); $ config_big_thumb ['source _ image'] = $ data ['full _ path']; $ config_big_thumb ['new _ image'] = ". /upload/big_thumb /". date ("Y/m/d "). "/". $ data ['file _ name']; // Configuration Parameter for small thumbnails/* $ config_small_thumb ['image _ library'] = 'gd2 '; // gd2 Gallery $ config_small_thumb ['source _ image'] = $ data ['full _ path']; // source image $ config_small_thumb ['new _ image'] = ". /upload/small_thumb /". date ("Y/m/d "). "/". $ data ['file _ name']; // large thumbnail $ config_small_thumb ['create _ thumb'] = true; // create a thumbnail $ config_small_thumb ['maintain _ ratio '] = true; $ config_small_thumb ['width'] = 100; // width of the thumbnail $ config_small_thumb ['height'] = 100; // height of the thumbnail $ config_small_thumb ['thumb _ marker'] = "_ 100_100 "; // Add "_ 100_100" to the thumbnail name ", it can represent a 100*100 thumbnail * // Configuration Parameter for a small thumbnail $ config_small_thumb = array ('image _ library' => 'gd2 ', // gd2 gallery 'source _ image' => $ data ['full _ path'], // source image 'new _ image' => ". /upload/small_thumb /". date ("Y/m/d "). "/". $ data ['file _ name'], // large thumbnail 'create _ thumb' => true, // whether to create a thumbnail 'maintain _ ratio '=> true, 'width' => 100, // The width of the thumbnail 'height' => 100, // The height of the thumbnail 'thumb _ marker' => "_ 100_100" // Add "_ 300_300" after the thumbnail name to indicate a 300*300 thumbnail ); // $ this-> load-> library ("image_lib", $ config_thumb); $ this-> image_lib-> initialize ($ config_big_thumb ); $ this-> image_lib-> resize (); // generate a big thumbnail $ this-> image_lib-> initialize ($ config_small_thumb); $ this-> image_lib-> resize (); // generate small thumbnails // Insert the database $ data_array = array ('category _ id' => $ category_id, 'pic _ url' => ". /upload/source /". date ("Y/m/d "). "/". $ data ['file _ name'], 'addtime' => time (), 'is _ stop' => 1, 'sort '=> 0, 'Gender' => $ _ POST ["gender"], 'link _ url' => $ _ POST ["link_url"], 'User _ id' => intval ($ this-> cur_user ['user _ id']); $ this-> category_model-> add_category_banner ($ data_array );}} $ con_arr [] = "category_id = '{$ category_id}'"; if ($ gender = '') {$ gender = 0 ;} $ con_arr [] = "gender = '{$ gender}'"; $ condition = implode ('and', $ con_arr ); $ banner_list = $ this-> category_model-> get_banner_all ($ condition); $ this-> tp-> assign ('banner _ list', $ banner_list ); $ this-> tp-> assign ('base _ url', base_url (); $ this-> tp-> assign ('gender', $ gender ); $ this-> tp-> assign ('category _ id', $ category_id); $ this-> tp-> display ("category/edit_list_page_banner.php ");}

Configuration items related to thumbnails In the config. php file:

// Configuration Parameter $ config_big_thumb = array ('image _ library' => 'gd2', // gd2 gallery 'create _ thumb' => true, // whether to create a thumbnail 'maintain _ ratio '=> true, 'width' => 300, // The thumbnail width 'height' => 300, // The height of the thumbnail 'thumb _ marker' => "_ 300_300" // Add "_ 300_300" after the thumbnail name to indicate a 300*300 thumbnail );

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.