CI架構檔案上傳類及影像處理類用法分析,ci檔案上傳
本文執行個體講述了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");//載入影像處理類庫 //第一種方式:大縮圖的配置參數 /* $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;//是否建立縮圖 $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的縮圖 */ //第二種:大縮圖的配置參數 /* $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,//是否建立縮圖 'maintain_ratio' => true, 'width' => 300,//縮圖寬度 'height' => 300,//縮圖的高度 'thumb_marker'=>"_300_300"//縮圖名字後加上 "_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']; //小縮圖的配置參數 /* $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;//是否建立縮圖 $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的縮圖 */ //小縮圖的配置參數 $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,//是否建立縮圖 'maintain_ratio' => true, 'width' => 100,//縮圖寬度 'height' => 100,//縮圖的高度 'thumb_marker'=>"_100_100"//縮圖名字後加上 "_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縮圖 //插入資料庫 $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檔案中有關縮圖的配置項:
//大縮圖的配置參數$config_big_thumb=array( 'image_library' => 'gd2',//gd2圖庫 'create_thumb' => true,//是否建立縮圖 'maintain_ratio' => true, 'width' => 300,//縮圖寬度 'height' => 300,//縮圖的高度 'thumb_marker'=>"_300_300"//縮圖名字後加上 "_300_300",可以代表是一個300*300的縮圖);
更多關於CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)架構進階教程》、《php優秀開發架構總結》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《Zend FrameWork架構入門教程》、《php物件導向程式設計入門教程》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》
希望本文所述對大家基於CodeIgniter架構的PHP程式設計有所協助。
http://www.bkjia.com/PHPjc/1127857.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1127857.htmlTechArticleCI架構檔案上傳類及影像處理類用法分析,ci檔案上傳 本文執行個體講述了CI架構檔案上傳類及影像處理類用法。分享給大家供大家參考,具體如...