CI Framework file Upload class and image processing class usage analysis, ci file upload _php tutorial

Source: Internet
Author: User
Tags image processing library codeigniter zend framework

CI Framework file Upload class and image processing class usage analysis, CI file upload


This article describes the CI framework file upload class and image processing class usage. Share to everyone for your reference, as follows:

List page banner picture public function Edit_list_page_banner ($category _id= "") {$category _id= empty ($category _id)? $_post["  category_id "]: $category _id; Upload image if (isset ($_post["key"]) && $_post["key"] = = "Upload") {/* 1.set_upload_path */$config [' Upload_pat H ']= "./upload/source/". Date ("y/m/d");//File Upload directory if (!file_exists ("./upload/source/". Date ("y/m/d")) {mkdir ("./ upload/source/". Date (" y/m/d "), 0777,true);//The original 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 '))///form Name= "UserFile" {//upload succeeded, generate two thumbnails $data = $this->upload-> Data ();//returns information about the uploaded image $this->load->library ("image_lib ");//load Image processing library//First way: Configuration parameters for large thumbnails/* $config _big_thumb[' image_library '] = ' gd2 ';//gd2 gallery $config _big_thumb[' s Ource_image '] = $data [' Full_path '];//original $config _big_thumb[' new_image '] = "./upload/big_thumb/". Date ("y/m/d"). " /". $data [' file_name '];//large thumbnail $config _big_thumb[' create_thumb '] = true;//whether to create thumbnails $config _big_thumb[' maintain_ratio '    ] = true; $config _big_thumb[' width ' = 300;//thumbnail width $config _big_thumb[' height ') = 300;//thumbnail height $config _big_thumb[' thumb_marker ' ]= "_300_300";//thumbnail name plus "_300_300", can represent a 300*300 thumbnail *///Second: Configuration parameters for large thumbnails/* $config _big_thumb=array (' Imag E_library ' + ' gd2 ',//gd2 gallery ' source_image ' and $data [' Full_path '],//original ' new_image ' and ' = './upload/big_thumb/ ". Date (" y/m/d ")." /". $data [' file_name '],//large thumbnail ' create_thumb ' = true,//create thumbnail ' maintain_ratio ' = True, ' width ' = 30    0,//thumbnail width ' height ' = 300,//thumbnail height ' thumb_marker ' + ' _300_300 '//thumbnail name plus ' _300_300 ', which can represent a 300*300 thumbnail); */    The third way: the partial configuration information is placed in the config.php file $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 parameters for small thumbnails/* $config _small_thumb[' image_library '] = ' gd2 ';//gd2 gallery $config _small_thumb[' source_image '] = $data [' Full_path '];//original $config _small_thumb[' new_image '] = "./upload/small_thumb/". Date ("y/m/d"). " /". $data [' file_name '];//large thumbnail $config _small_thumb[' create_thumb '] = true;//whether to create thumbnails $config _small_thumb[' Maintain_    Ratio '] = true; $config _small_thumb[' width ' = 100;//thumbnail width $config _small_thumb[' height ') = 100;//thumbnail height $config _small_thumb[' thumb_m Arker ']= "_100_100";//thumbnail name after adding "_100_100", can represent a 100*100 thumbnail *////small thumbnail configuration parameters $config _small_thumb=array (' Image_ Library ' + ' GD2 ',//gd2 gallery ' source_image ' and $data [' Full_path '],//original ' new_image ' = './upload/small_thumb/ ". Date (" y/m/d ")." /". $data[' file_name '],//large thumbnail ' create_thumb ' + true,//whether to create thumbnail ' maintain_ratio ' = True, ' width ' = + 100,//thumbnail    Figure width ' height ' = 100,//thumbnail height ' thumb_marker ' = ' _100_100 '//thumbnail name plus ' _300_300 ', which can represent a 300*300 thumbnail);    $this->load->library ("Image_lib", $config _thumb);    $this->image_lib->initialize ($config _big_thumb);    $this->image_lib->resize ();//generate Big thumbnail $this->image_lib->initialize ($config _small_thumb);     $this->image_lib->resize ();//Generate small thumbnail//insert 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[' Gen    Der "], ' 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 for thumbnails in the config.php file:

Large thumbnail configuration parameters $config_big_thumb=array (' image_library ' = ' gd2 ',//gd2 gallery ' create_thumb ' + true,//whether to create thumbnails ' maintain _ratio ' = ' = True, ' width ' = 300,//thumbnail width ' height ' + 300,//thumbnail height ' thumb_marker ' + ' _300_300 '//thumbnail name added "_300_ 300 ", can be represented as a 300*300 thumbnail);

More interested in CodeIgniter related content readers can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP Excellent Development Framework Summary", "thinkphp Getting Started", " Summary of common methods of thinkphp, "Introduction to Zend Framework Frame", "Introduction to PHP Object-oriented Programming", "Introduction to Php+mysql Database Operation" and "PHP common database Operation Skills Summary"

It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.

http://www.bkjia.com/PHPjc/1127857.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127857.html techarticle CI Framework file upload class and image processing class usage analysis, CI file upload This paper describes the CI framework file upload class and image processing class usage. Share to everyone for your reference, specific as ...

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