CI frame file Upload class and image processing class usage Analysis _php example

Source: Internet
Author: User
Tags mkdir codeigniter zend framework

This example describes the CI framework file upload class and image processing class usage. Share to everyone for your reference, specific 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 picture if (isset ($_post["key")) && $_post["key"] = = "Upload") {/* 1.set_upload_path * * $config [' Uploa D_path ']= './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)//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 '))//The form name= "UserFile" {//uploaded successfully, generate two thumbnails $data = $this->UPLOAD-&G T;data ()//Returns the information of the uploaded picture $this-≫load->library ("Image_lib"); Load the image processing class library//The first way: Large thumbnail configuration Parameters/* $config _big_thumb[' image_library '] = ' gd2 '; GD2 gallery $config _big_thumb[' source_image '] = $data [' Full_path '];//original artwork $config _big_thumb[' new_image '] = "./upload/big_t humb/". 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_marke
     R ']= "_300_300"//thumbnail name plus "_300_300", can represent a 300*300 thumbnail//second: Large thumbnail configuration Parameters/* $config _big_thumb=array ( ' Image_library ' => ' gd2 ',//gd2 gallery ' source_image ' => $data [' Full_path '],//' The original image ' New_image ' => './upload/b ig_thumb/". Date (" y/m/d ")."  /". $data [' file_name '],//large thumbnail ' create_thumb ' => true,//whether to create thumbnails ' Maintain_ratio ' => true, ' width ' => 300,//thumbnail width ' height ' => 300,//thumbnail heights ' thumb_marker ' => ' _300_300 '//abbreviationAfter the figure name plus "_300_300", can represent is a 300*300 thumbnail);
    //A third way: To put part of the configuration information 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 '] = $dat a[' Full_path '];//artwork $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_ra
    Tio '] = true; $config _small_thumb[' width '] = 100;//thumbnail width $config _small_thumb[' height ' = 100;//thumbnail height $config _small_thumb[' thumb _marker ']= "_100_100"//thumbnail name plus "_100_100", can represent a 100*100 thumbnail///small thumbnail configuration parameters $config _small_thumb=array (' Image_library ' => ' gd2 ',//gd2 gallery ' source_image ' => $data [' Full_path '],//originalFigure ' New_image ' => "./upload/small_thumb/". Date ("y/m/d"). "  /". $data [' file_name '],//large thumbnail ' create_thumb ' => true,//whether to create thumbnails ' Maintain_ratio ' => true, ' width ' =>
    The 100,//thumbnail width ' height ' => 100,//thumbnail height ' thumb_marker ' => ' _100_100 '//thumbnail name plus ' _300_300 ' 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[
    "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");

 }

config.php configuration items in the file for thumbnails:

Configuration parameters for large thumbnails
$config _big_thumb=array (
 ' image_library ' => ' gd2 ',//gd2 gallery
 ' create_thumb ' => true,// Create thumbnail
 ' maintain_ratio ' => true,
 ' width ' => 300,//thumbnail width
 ' height ' => 300,//thumbnail height
 ' thumb_ Marker ' => "_300_300"//thumbnail name plus "_300_300" can represent a 300*300 thumbnail
);

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.