CI框架文件上傳類及圖像處理類用法分析
來(lái)源:易賢網(wǎng) 閱讀:1270 次 日期:2016-08-22 14:24:42
溫馨提示:易賢網(wǎng)小編為您整理了“CI框架文件上傳類及圖像處理類用法分析”,方便廣大網(wǎng)友查閱!

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

//列表頁(yè)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");//載入圖像處理類庫(kù)

    //第一種方式:大縮略圖的配置參數(shù)

    /*

    $config_big_thumb['image_library'] = 'gd2';//gd2圖庫(kù)

    $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",可以代表是一個(gè)300*300的縮略圖

    */

    //第二種:大縮略圖的配置參數(shù)

    /*

    $config_big_thumb=array(

     'image_library' => 'gd2',//gd2圖庫(kù)

     '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",可以代表是一個(gè)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圖庫(kù)

    $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",可以代表是一個(gè)100*100的縮略圖

    */

    //小縮略圖的配置參數(shù)

    $config_small_thumb=array(

     'image_library' => 'gd2',//gd2圖庫(kù)

     '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",可以代表是一個(gè)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ù)庫(kù)

    $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)縮略圖的配置項(xiàng):

//大縮略圖的配置參數(shù)

$config_big_thumb=array(

 'image_library' => 'gd2',//gd2圖庫(kù)

 'create_thumb' => true,//是否創(chuàng)建縮略圖

 'maintain_ratio' => true,

 'width' => 300,//縮略圖寬度

 'height' => 300,//縮略圖的高度

 'thumb_marker'=>"_300_300"http://縮略圖名字后加上 "_300_300",可以代表是一個(gè)300*300的縮略圖

);

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

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:CI框架文件上傳類及圖像處理類用法分析
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)