簡單來說就是在自己CodeIgniter專案下加入幾個檔案
讓eclipse自動的出現提示
原文出處:http://www.web-and-development.com/codeigniter-and-eclipse-autocomplete/
在程式裡的另一個自己
2011年10月2日 星期日
Python 開發環境架設
在學習任何程式語言的第一步不外乎就是架設環境
在windows裡學習Python開發中
需要安裝python-3.2.2.msi
安裝完需要設定環境變數Path
多加D:\Python32;D:\Python32\Tools\Scripts;這兩項(視安裝目錄所變)
才讓在windows裡跑Python
還需要一套IDE(雖然有內建Python GUI但是很陽春)
在這裡我選用eclipse因為之前開發PHP也是用這套
eclipse真的是包山包海什麼都有
開發Python需要pydev套件才能在eclipse裡下run
安裝完還需要在eclipse裡的pydev裡的Interpreter -Python
設定指向python的安裝目錄的python.exe
這樣就能在eclipse下執行python了
如果需要要在apache下跑需要python就需要安裝mod_python-3.3.1模組了
在windows裡學習Python開發中
需要安裝python-3.2.2.msi
安裝完需要設定環境變數Path
多加D:\Python32;D:\Python32\Tools\Scripts;這兩項(視安裝目錄所變)
才讓在windows裡跑Python
還需要一套IDE(雖然有內建Python GUI但是很陽春)
在這裡我選用eclipse因為之前開發PHP也是用這套
eclipse真的是包山包海什麼都有
開發Python需要pydev套件才能在eclipse裡下run
安裝完還需要在eclipse裡的pydev裡的Interpreter -Python
設定指向python的安裝目錄的python.exe
這樣就能在eclipse下執行python了
如果需要要在apache下跑需要python就需要安裝mod_python-3.3.1模組了
2011年8月4日 星期四
[PHP]取得檔案的副檔名[轉載]
//假設檔名
$filename = 'mypic.gif';
// 1. 使用陣列函式 "explode/end" 方式
$ext = end(explode('.', $filename));
// 2. 使用字串函式 "strrchr" 方式
$ext = substr(strrchr($filename, '.'), 1);
// 3. 使用字串函式 "strrpos" 方式
$ext = substr($filename, strrpos($filename, '.') + 1);
// 4. 使用正規式 "preg_replace" 方式
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
// 5. 特別(從來沒用過)方式
// 參考: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];
pathinfo(path,options)PATHINFO_DIRNAME:取得資料夾路徑 PATHINFO_BASENAME:取得整個檔名(主+副) PATHINFO_EXTENSION:取得副檔名 PATHINFO_FILENAME :取得主檔名pathinfo() 返回一個關聯數組包含有 path 的信息
包括以下的數組元素:[dirname] [basename] [extension][filename]2011年8月2日 星期二
[PHP]用來-轉檔-縮圖-輸出
<?php
class resize_img
{
var $image_path = '';
//holds the image path
var $sizelimit_x = 250;
//the limit of the image width
var $sizelimit_y = 250;
//the limit of the image height
var $image_resource = '';
//holds the image resource
var $keep_proportions = true;
//if true it keeps the image proportions when resized
var $resized_resource = '';
//holds the resized image resource
var $hasGD = false;
var $output = 'SAME';
//can be JPG, GIF, PNG, or SAME (same will save as old type)
function resize_img()
{
if( function_exists('gd_info') ){ $this->hasGD = true; } //---判斷GD函式是否支援
}
function resize_image( $image_path )
{
if( $this->hasGD === false ){ return false; }
//沒有GD支援
list($img_width, $img_height, $img_type, $img_attr) = @getimagesize( $image_path );
//這是會得到的圖像的寬度,高度和格式
if( ( $img_width != 0 ) || ( $img_width != 0 ) )
//確保它是正確裝入
{
switch( $img_type )
{
case 1:
//GIF
$this->image_resource = @imagecreatefromgif( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'GIF'; }
break;
case 2:
//JPG
$this->image_resource = @imagecreatefromjpeg( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'JPG'; }
break;
case 3:
//PNG
$this->image_resource = @imagecreatefrompng( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'PNG'; }
}
if( $this->image_resource === '' ){ return false; }
//它無法加載圖像
}
else{ return false; }
//發生無法預期的錯誤
if( $this->keep_proportions === true )
{
if( ($img_width-$this->sizelimit_x) > ($img_height-$this->sizelimit_y) )
{
//如果IMG寬度 大於規定的大小限制,我們的寬度將做縮減
$scalex = ( $this->sizelimit_x / $img_width );
$scaley = $scalex;
}
else
{
//如果IMG高度 大於規定的大小限制,我們的高度將做縮減
$scalex = ( $this->sizelimit_y / $img_height );
$scaley = $scalex;
}
}
else
{
$scalex = ( $this->sizelimit_x / $img_width );
$scaley = ( $this->sizelimit_y / $img_height );
//只是使圖像適合圖像的大小限制
if( $scalex > 1 ){ $scalex = 1; }
if( $scaley > 1 ){ $scaley = 1; }
//圖像小於限制所以不做變更
}
$new_width = $img_width * $scalex;//計算新的寬
$new_height = $img_height * $scaley;//計算新的高
$this->resized_resource = @imagecreatetruecolor( $new_width, $new_height );
//創建一個圖像資源,用寬度和高度的大小限制(或新的調整比例)
if( function_exists( 'imageantialias' )){ @imageantialias( $this->resized_resource, true ); }
//有助於在質量的圖像被調整判斷是否有此函式
@imagecopyresampled( $this->resized_resource, $this->image_resource, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height );
//調整張圖片上調整資源
@imagedestroy( $this->image_resource );
//清空舊的圖像資源
return true;
}
//判斷輸出為什麼格式
function save_resizedimage( $path, $name )
{
switch( strtoupper($this->output) )
{
case 'GIF':
//GIF
@imagegif( $this->resized_resource, $path . $name . '.gif' );
break;
case 'JPG':
//JPG
@imagejpeg( $this->resized_resource, $path . $name . '.jpg' );
break;
case 'PNG':
//PNG
@imagepng( $this->resized_resource, $path . $name . '.png' );
}
}
//--此函式用來在頁面顯示圖片
function output_resizedimage()
{
$the_time = time();
header('Last-Modified: ' . date( 'D, d M Y H:i:s', $the_time ) . ' GMT');
header('Cache-Control: public');
switch( strtoupper($this->output) )
{
case 'GIF':
//GIF
header('Content-type: image/gif');
@imagegif( $this->resized_resource );
break;
case 'JPG':
//JPG
header('Content-type: image/jpg');
@imagejpeg( $this->resized_resource );
break;
case 'PNG':
//PNG
header('Content-type: image/png');
@imagepng( $this->resized_resource );
}
}
function destroy_resizedimage()
{
@imagedestroy( $this->resized_resource );
@imagedestroy( $this->image_resource );
}
}
?>
/*範例-----可以用來-轉檔-縮圖-輸出
$imgresize = new resize_img();
$imgresize->sizelimit_x = 100;
$imgresize->sizelimit_y = 100;
$imgresize->keep_proportions = true;
$imgresize->output = 'GIF';
$filename = uniqid().rand(1000,9999);
if( $imgresize->resize_image( $_FILES['Filedata']['tmp_name'] ) === false )
{
echo 'ERROR!';
}
else
{
$imgresize->save_resizedimage( 'D:/www/test/thumbnails/', $filename );
}
$imgresize->destroy_resizedimage();
*/
class resize_img
{
var $image_path = '';
//holds the image path
var $sizelimit_x = 250;
//the limit of the image width
var $sizelimit_y = 250;
//the limit of the image height
var $image_resource = '';
//holds the image resource
var $keep_proportions = true;
//if true it keeps the image proportions when resized
var $resized_resource = '';
//holds the resized image resource
var $hasGD = false;
var $output = 'SAME';
//can be JPG, GIF, PNG, or SAME (same will save as old type)
function resize_img()
{
if( function_exists('gd_info') ){ $this->hasGD = true; } //---判斷GD函式是否支援
}
function resize_image( $image_path )
{
if( $this->hasGD === false ){ return false; }
//沒有GD支援
list($img_width, $img_height, $img_type, $img_attr) = @getimagesize( $image_path );
//這是會得到的圖像的寬度,高度和格式
if( ( $img_width != 0 ) || ( $img_width != 0 ) )
//確保它是正確裝入
{
switch( $img_type )
{
case 1:
//GIF
$this->image_resource = @imagecreatefromgif( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'GIF'; }
break;
case 2:
//JPG
$this->image_resource = @imagecreatefromjpeg( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'JPG'; }
break;
case 3:
//PNG
$this->image_resource = @imagecreatefrompng( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'PNG'; }
}
if( $this->image_resource === '' ){ return false; }
//它無法加載圖像
}
else{ return false; }
//發生無法預期的錯誤
if( $this->keep_proportions === true )
{
if( ($img_width-$this->sizelimit_x) > ($img_height-$this->sizelimit_y) )
{
//如果IMG寬度 大於規定的大小限制,我們的寬度將做縮減
$scalex = ( $this->sizelimit_x / $img_width );
$scaley = $scalex;
}
else
{
//如果IMG高度 大於規定的大小限制,我們的高度將做縮減
$scalex = ( $this->sizelimit_y / $img_height );
$scaley = $scalex;
}
}
else
{
$scalex = ( $this->sizelimit_x / $img_width );
$scaley = ( $this->sizelimit_y / $img_height );
//只是使圖像適合圖像的大小限制
if( $scalex > 1 ){ $scalex = 1; }
if( $scaley > 1 ){ $scaley = 1; }
//圖像小於限制所以不做變更
}
$new_width = $img_width * $scalex;//計算新的寬
$new_height = $img_height * $scaley;//計算新的高
$this->resized_resource = @imagecreatetruecolor( $new_width, $new_height );
//創建一個圖像資源,用寬度和高度的大小限制(或新的調整比例)
if( function_exists( 'imageantialias' )){ @imageantialias( $this->resized_resource, true ); }
//有助於在質量的圖像被調整判斷是否有此函式
@imagecopyresampled( $this->resized_resource, $this->image_resource, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height );
//調整張圖片上調整資源
@imagedestroy( $this->image_resource );
//清空舊的圖像資源
return true;
}
//判斷輸出為什麼格式
function save_resizedimage( $path, $name )
{
switch( strtoupper($this->output) )
{
case 'GIF':
//GIF
@imagegif( $this->resized_resource, $path . $name . '.gif' );
break;
case 'JPG':
//JPG
@imagejpeg( $this->resized_resource, $path . $name . '.jpg' );
break;
case 'PNG':
//PNG
@imagepng( $this->resized_resource, $path . $name . '.png' );
}
}
//--此函式用來在頁面顯示圖片
function output_resizedimage()
{
$the_time = time();
header('Last-Modified: ' . date( 'D, d M Y H:i:s', $the_time ) . ' GMT');
header('Cache-Control: public');
switch( strtoupper($this->output) )
{
case 'GIF':
//GIF
header('Content-type: image/gif');
@imagegif( $this->resized_resource );
break;
case 'JPG':
//JPG
header('Content-type: image/jpg');
@imagejpeg( $this->resized_resource );
break;
case 'PNG':
//PNG
header('Content-type: image/png');
@imagepng( $this->resized_resource );
}
}
function destroy_resizedimage()
{
@imagedestroy( $this->resized_resource );
@imagedestroy( $this->image_resource );
}
}
?>
/*範例-----可以用來-轉檔-縮圖-輸出
$imgresize = new resize_img();
$imgresize->sizelimit_x = 100;
$imgresize->sizelimit_y = 100;
$imgresize->keep_proportions = true;
$imgresize->output = 'GIF';
$filename = uniqid().rand(1000,9999);
if( $imgresize->resize_image( $_FILES['Filedata']['tmp_name'] ) === false )
{
echo 'ERROR!';
}
else
{
$imgresize->save_resizedimage( 'D:/www/test/thumbnails/', $filename );
}
$imgresize->destroy_resizedimage();
*/
[PHP]頁面連接函式
//一面多少個資料
$results_per_page = 50;
//多少個頁面
$num_pages = ceil(count($friend['data'])/$results_per_page);
//當前頁面
$cur_page = isset($_GET['page']) ? $_GET['page'] : 1;
//定位該頁面的第一筆資料
$skip = (($cur_page - 1 )*$results_per_page);
$friends=array();
//一次只拿50個資料
$friends = array_slice($friend['data'],$skip,$results_per_page);
//------------------------------------------------------------
function generate_page_links($cur_page, $num_pages) {
$page_links = '';
$before = $cur_page - 4;
$after = $cur_page + 4;
($before < 1 ? $before=1:'');
($after > $num_pages ? $after = $num_pages:'');
// If this page is not the first page, generate the "previous" link
if ($cur_page > 1) {
$page_links .= '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($cur_page - 1) . '"><-</a> ';
}
else {
$page_links .= '<- ';
}
// Loop through the pages generating the page number links
for ($before; $before <= $after ;$before++) {
if ($cur_page == $before) {
$page_links .= ' ' . $before;
}
else {
$page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $before . '"> ' . $before . '</a>';
}
}
// If this page is not the last page, generate the "next" link
if ($cur_page < $after) {
$page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($cur_page + 1) . '">-></a>';
}
else {
$page_links .= ' ->';
}
return $page_links;
}
$results_per_page = 50;
//多少個頁面
$num_pages = ceil(count($friend['data'])/$results_per_page);
//當前頁面
$cur_page = isset($_GET['page']) ? $_GET['page'] : 1;
//定位該頁面的第一筆資料
$skip = (($cur_page - 1 )*$results_per_page);
$friends=array();
//一次只拿50個資料
$friends = array_slice($friend['data'],$skip,$results_per_page);
//------------------------------------------------------------
function generate_page_links($cur_page, $num_pages) {
$page_links = '';
$before = $cur_page - 4;
$after = $cur_page + 4;
($before < 1 ? $before=1:'');
($after > $num_pages ? $after = $num_pages:'');
// If this page is not the first page, generate the "previous" link
if ($cur_page > 1) {
$page_links .= '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($cur_page - 1) . '"><-</a> ';
}
else {
$page_links .= '<- ';
}
// Loop through the pages generating the page number links
for ($before; $before <= $after ;$before++) {
if ($cur_page == $before) {
$page_links .= ' ' . $before;
}
else {
$page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $before . '"> ' . $before . '</a>';
}
}
// If this page is not the last page, generate the "next" link
if ($cur_page < $after) {
$page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($cur_page + 1) . '">-></a>';
}
else {
$page_links .= ' ->';
}
return $page_links;
}
2011年7月31日 星期日
[PHP]過濾XXS函式
<?php
function sacarXss($val){
$val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val);
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < strlen($search); $i++) {
$val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
$val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
}
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
$ra = array_merge($ra1, $ra2);
$found = true;
while ($found == true) {
$val_before = $val;
for ($i = 0; $i < sizeof($ra); $i++) {
$pattern = '/';
for ($j = 0; $j < strlen($ra[$i]); $j++) {
if ($j > 0) {
$pattern .= '(';
$pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?';
$pattern .= '|(�{0,8}([9][10][13]);?)?';
$pattern .= ')?';
}
$pattern .= $ra[$i][$j];
}
$pattern .= '/i';
$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2);
$val = preg_replace($pattern, $replacement, $val);
if ($val_before == $val) {
$found = false;
}
}
}
return $val;
}
?>
function sacarXss($val){
$val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val);
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < strlen($search); $i++) {
$val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
$val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
}
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
$ra = array_merge($ra1, $ra2);
$found = true;
while ($found == true) {
$val_before = $val;
for ($i = 0; $i < sizeof($ra); $i++) {
$pattern = '/';
for ($j = 0; $j < strlen($ra[$i]); $j++) {
if ($j > 0) {
$pattern .= '(';
$pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?';
$pattern .= '|(�{0,8}([9][10][13]);?)?';
$pattern .= ')?';
}
$pattern .= $ra[$i][$j];
}
$pattern .= '/i';
$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2);
$val = preg_replace($pattern, $replacement, $val);
if ($val_before == $val) {
$found = false;
}
}
}
return $val;
}
?>
訂閱:
文章 (Atom)