CI框架文件上傳類及圖像處理類用法分析
本文實(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)文章
Yii實(shí)現(xiàn)Command任務(wù)處理的方法詳解
這篇文章主要介紹了Yii實(shí)現(xiàn)Command任務(wù)處理的方法,結(jié)合實(shí)例形式分析了Yii配置、加載及使用Command任務(wù)處理的步驟與相關(guān)技巧,需要的朋友可以參考下2016-07-07thinkPHP3.2簡單實(shí)現(xiàn)文件上傳的方法
這篇文章主要介紹了thinkPHP3.2簡單實(shí)現(xiàn)文件上傳的方法,重點(diǎn)介紹了thinkPHP實(shí)現(xiàn)文件上傳功能的控制器文件相關(guān)技巧,需要的朋友可以參考下2016-05-05php 替換文章中的圖片路徑,下載圖片到本地服務(wù)器的方法
下面小編就為大家分享一篇php 替換文章中的圖片路徑,下載圖片到本地服務(wù)器的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02php循環(huán)創(chuàng)建目錄示例分享(php創(chuàng)建多級目錄)
這篇文章主要介紹了php循環(huán)創(chuàng)建目錄示例,原理就是不斷的嘗試創(chuàng)建上層目錄,依此類推,需要的朋友可以參考下2014-03-03Zend Framework教程之模型Model基本規(guī)則和使用方法
這篇文章主要介紹了Zend Framework教程之模型Model基本規(guī)則和使用方法,結(jié)合實(shí)例形式詳細(xì)分析了Zend Framework中模型的原理與具體使用技巧,需要的朋友可以參考下2016-03-03關(guān)于PHP中Session文件過多的問題及session文件保存位置
PHP的默認(rèn)機(jī)制:每一次php請求,會有1/100的概率(默認(rèn)值)觸發(fā)“session回收”。接下來通過本文給大家介紹關(guān)于PHP中Session文件過多的問題及session文件保存位置,需要的朋友參考下2016-03-03Zend Framework入門教程之Zend_Config組件用法詳解
這篇文章主要介紹了Zend Framework入門教程之Zend_Config組件用法,結(jié)合實(shí)例形式分析了Zend_Config組件針對各種類型配置文件操作的相關(guān)技巧,需要的朋友可以參考下2016-12-12