CodeIgniter超簡易發信

[php]
$email_config = Array(
‘mailtype’ => ‘html’

);
$this->load->library(’email’,$email_config);
$this->email->from(‘superlevin@gmail.com’, ‘林壽山’); //寄件者
$this->email->to(‘123@gmail.com’); // 收件者
//$this->email->cc(‘123cc@gmail.com’); // 副本
//$this->email->bcc(‘123bcc@gmail.com’); // 密件副本

$this->email->subject(‘成功通知信’); // 主旨
$this->email->message(‘<b>報名成功</b>’); //內容
$this->email->send();
[/php]

CodeIgniter上傳圖檔以及縮圖

[php]
// 縮圖
function _createThumbnail($fileName, $isThumb, $thumbMarker="", $width, $height) {
// 參數
$config[‘image_library’] = ‘gd2’;
$config[‘source_image’] = $fileName;
$config[‘create_thumb’] = $isThumb;
$config[‘maintain_ratio’] = TRUE;
$config[‘master_dim’] = ‘width’;
if(isset($thumbMarker) && $thumbMarker!=""){
$config[‘thumb_marker’] = $thumbMarker;
}
$config[‘width’] = $width;
$config[‘height’] = $height;

$this->load->library(‘image_lib’, $config);
$this->image_lib->clear();
$this->image_lib->initialize($config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}
[/php]
上傳
[php]
function uploadimage(){
$name = $this->input->get_post(‘my_file’);
$config[‘upload_path’] = ‘./uploads/’;
$config[‘allowed_types’] = ‘gif|jpg|png’;
$config[‘file_name’] = $name;
$config[‘overwrite’] = true;
$config[‘max_size’] = 4096;
//$config[‘max_width’] = 5000;
//$config[‘max_height’] = 5000;
$this->load->library(‘upload’, $config);
if ( ! $this->upload->do_upload())
{
$data[‘errormsg’] = array(‘error’ => $this->upload->display_errors());
$this->load->view(‘welcome_message’, $data);
}
else
{
$fInfo = $this->upload->data();
$this->_createThumbnail($fInfo[‘full_path’],TRUE,"",330,480);
$this->_createThumbnail($fInfo[‘full_path’],TRUE,"_tn",110,160);

$data[‘filename’]=$this->upload->data(‘file_name’);
$this->load->view(‘welcome_message’,$data);
}

}
[/php]

CodeIgniter解決CSS路徑問題

使用CodeIgniter撰寫網頁很方便,不過會遇到的問題常常是css、image的路徑問題。
除了使用絕對路徑外,也可以使用HTML base Tag來指定基準的URL。
[php]
// 記得要load helper url
$this->load->helper(‘url’);
// 在 view 中的HTML加上
<base href="<?php echo base_url();?>"/>
[/php]

CodeIgniter使用Securimage驗證碼方式

1 https://www.phpcaptcha.org/ 下載後解壓縮到application\libraries\securimage
2 controller中新增function

[php]
function securimage() {
$this->load->library(‘securimage’);
$img = new Securimage();
$img->show();
}
[/php]

3 view裡面增加

[html]
<img id="captcha" src="<?=site_url(‘[controller classname]/securimage’)?>" alt=’captcha’ id=’captcha’ />
<a href="#" onclick=" document.getElementById(‘captcha’).src = document.getElementById(‘captcha’).src + ‘?’ + (new Date()).getMilliseconds()">重新產生驗證碼</a>
[/html]

4 驗證

[php]
$captchacode= $this->input->post(‘captchacode’);
$this->load->library(‘securimage’);
if ($this->securimage->check($captchacode)==true){
redirect(‘index’);
}
[/php]

CodeIgniter學習筆記 – 安裝

主站(英文)中文站下載CodeIgniter_x.x.x.zip,解壓縮將index.php及application、system二個目錄上傳到主機。

1.為了安全性,建議把application、system二個目錄移到系統目錄

但需要修改 index.php

$system_path = ‘system’;

$application_folder = ‘application’;

2.如果需要資料庫設定,修改application\config\database.php

$db[‘default’][‘hostname’] = ‘localhost’;
$db[‘default’][‘username’] = ”;
$db[‘default’][‘password’] = ”;
$db[‘default’][‘database’] = ”;

如果沒有問題的話就可以看到下面的頁面。

Welcome to CodeIgniter

 

 

 

 

 

相關連結:

CodeIgniter on GitHub

CodeIgniter手冊(英文)

CodeIgniter手冊(中文)

CodeIgniter論壇(英文)

CodeIgniter論壇(中文)

CodeIgniter偵測使用者瀏覽器

方式一:使用user_agent跟redirect
[php]
$this->load->library(‘user_agent’);
$this->load->helper(‘url’);
if ($this->agent->browser() == ‘Internet Explorer’ and $this->agent->version() <= 7)
redirect(‘/unsupported-browser’);
[/php]

方式二:使用 http://mobiledetect.net
[php]
$this -> load -> library(‘Mobile_Detect’);
$detect = new Mobile_Detect();
if ($detect->is(‘Chrome’) || $detect->is(‘iOS’)) {

}
[/php]

CodeIgniter安裝

一直習慣使用純PHP寫程式,不過最近看到許多徵才網站都寫著會使用CodeIgniter框架更佳。於是就來學習使用看看,沒想到還真的簡單易用,分享給大家。

 

1. 到CodeIgniter官方網站下載(http://ellislab.com/codeigniter),或是目前台灣也有繁體中文網站(http://www.codeigniter.org.tw/)。

2.下載後解壓縮,只要上傳application、system二個目錄及index.php到主機即可。

3.確認上傳後,就可以看到Welcome to CodeIgniter!

CodeIgniter

4.恭禧您!已經踏入CodeIgniter了XDDD

Delphi XE5 30天學習暫停五天

晚安!突然有網友來信問了怎麼停頓沒教了呢?其實不是沒有教啦~只是最近在忙著手上的專案。剛好手上在從事 餐飲業的POS系統開發以及 Codeigniter 結合 bootstrap3的案子,這正好又可以寫一些文章分享了!

請大家耐心等候囉!