欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CI框架文件上傳類及圖像處理類用法分析

 更新時間:2016年05月18日 09:15:56   作者:yanhui_wei  
這篇文章主要介紹了CI框架文件上傳類及圖像處理類用法,設(shè)計CI框架圖片上傳及縮略圖操作的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了CI框架文件上傳類及圖像處理類用法。分享給大家供大家參考,具體如下:

//列表頁banner圖片
public function edit_list_page_banner($category_id=""){
  $category_id= empty($category_id)?$_POST["category_id"]:$category_id;
  //上傳圖片
  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);//原圖路徑
   }
   if(!file_exists("./upload/big_thumb/".date("Y/m/d"))){
    mkdir("./upload/big_thumb/".date("Y/m/d"),0777,true);//大縮略圖路徑
   }
   if(!file_exists("./upload/small_thumb/".date("Y/m/d"))){
    mkdir("./upload/small_thumb/".date("Y/m/d"),0777,true);//小縮略圖路徑
   }
   $config['allowed_types']="gif|jpg|png|txt";//文件類型
   $config['max_size']="20000";//最大上傳大小
   $this->load->library("upload",$config);
   if($this->upload->do_upload('userfile'))//表單中name="userfile"
   {
    //上傳成功之后,生成兩張縮略圖
    $data=$this->upload->data();//返回上傳圖片的信息
    $this->load->library("image_lib");//載入圖像處理類庫
    //第一種方式:大縮略圖的配置參數(shù)
    /*
    $config_big_thumb['image_library'] = 'gd2';//gd2圖庫
    $config_big_thumb['source_image'] = $data['full_path'];//原圖
    $config_big_thumb['new_image'] = "./upload/big_thumb/".date("Y/m/d")."/".$data['file_name'];//大縮略圖
    $config_big_thumb['create_thumb'] = true;//是否創(chuàng)建縮略圖
    $config_big_thumb['maintain_ratio'] = true;
    $config_big_thumb['width'] = 300;//縮略圖寬度
    $config_big_thumb['height'] = 300;//縮略圖的高度
    $config_big_thumb['thumb_marker']="_300_300";//縮略圖名字后加上 "_300_300",可以代表是一個300*300的縮略圖
    */
    //第二種:大縮略圖的配置參數(shù)
    /*
    $config_big_thumb=array(
     'image_library' => 'gd2',//gd2圖庫
     'source_image' => $data['full_path'],//原圖
     'new_image' => "./upload/big_thumb/".date("Y/m/d")."/".$data['file_name'],//大縮略圖
     'create_thumb' => true,//是否創(chuàng)建縮略圖
     'maintain_ratio' => true,
     'width' => 300,//縮略圖寬度
     'height' => 300,//縮略圖的高度
     'thumb_marker'=>"_300_300"http://縮略圖名字后加上 "_300_300",可以代表是一個300*300的縮略圖
    );
    */
    //第三種方式:將部分配置信息放到了config.php文件中
    $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'];
    //小縮略圖的配置參數(shù)
    /*
    $config_small_thumb['image_library'] = 'gd2';//gd2圖庫
    $config_small_thumb['source_image'] = $data['full_path'];//原圖
    $config_small_thumb['new_image'] = "./upload/small_thumb/".date("Y/m/d")."/".$data['file_name'];//大縮略圖
    $config_small_thumb['create_thumb'] = true;//是否創(chuàng)建縮略圖
    $config_small_thumb['maintain_ratio'] = true;
    $config_small_thumb['width'] = 100;//縮略圖寬度
    $config_small_thumb['height'] = 100;//縮略圖的高度
    $config_small_thumb['thumb_marker']="_100_100";//縮略圖名字后加上 "_100_100",可以代表是一個100*100的縮略圖
    */
    //小縮略圖的配置參數(shù)
    $config_small_thumb=array(
     'image_library' => 'gd2',//gd2圖庫
     'source_image' => $data['full_path'],//原圖
     'new_image' => "./upload/small_thumb/".date("Y/m/d")."/".$data['file_name'],//大縮略圖
     'create_thumb' => true,//是否創(chuàng)建縮略圖
     'maintain_ratio' => true,
     'width' => 100,//縮略圖寬度
     'height' => 100,//縮略圖的高度
     'thumb_marker'=>"_100_100"http://縮略圖名字后加上 "_300_300",可以代表是一個300*300的縮略圖
    );
    //$this->load->library("image_lib",$config_thumb);
    $this->image_lib->initialize($config_big_thumb);
    $this->image_lib->resize();//生成big縮略圖
    $this->image_lib->initialize($config_small_thumb);
    $this->image_lib->resize();//生成small縮略圖
    //插入數(shù)據(jù)庫
    $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文件中有關(guān)縮略圖的配置項:

//大縮略圖的配置參數(shù)
$config_big_thumb=array(
 'image_library' => 'gd2',//gd2圖庫
 'create_thumb' => true,//是否創(chuàng)建縮略圖
 'maintain_ratio' => true,
 'width' => 300,//縮略圖寬度
 'height' => 300,//縮略圖的高度
 'thumb_marker'=>"_300_300"http://縮略圖名字后加上 "_300_300",可以代表是一個300*300的縮略圖
);

更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論