顯示具有 php 標籤的文章。 顯示所有文章
顯示具有 php 標籤的文章。 顯示所有文章

2010年4月16日

手動安裝PHP5 on IIS6

IIS6(win2003)+PHP5 (ISAPI) 安裝攻略 (原文出處)
1. 確認 IIS 已經裝好,到 PHP 官網下載新版 PHP5 壓縮檔(ex.php-5.2.3-Win32.zip),
並且解壓縮(假設在 C:\PHP5)。
2. 將 C:\PHP5\php.ini-dist 改名為 php.ini,然後依需求編輯設定檔內容,範例:
include_path = ".;C:\Inetpub\wwwroot"
extension_dir = "C:\PHP5\ext"

magic_quotes_gpc = On
display_errors = On
error_reporting = E_ALL & ~E_NOTICE (預設 error_reporting = E_ALL 需關掉)
register_globals = Off
session.save_path = "C:\PHP5\tmp" (檢查此目錄是否存在)
upload_max_filesize = 2M (上傳檔案的最大size,可自行修改)
date.timezone = "Asia/Taipei"
SMTP = tts.tbmc.com.tw (Windows Only)
short_open_tag = On

//開啟需要的模組
extension=php_gd2.dll
extension=php_iconv.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_zip.dll
extension=php_pgsql.dll (for postgreSQL)

3. 對 C:\PHP5 目錄增加 IIS_WPG 群組及 IUSR_XXXX 使用者的讀取及執行權限。
(關鍵步驟,一定要兩個都增加,否則執行 PHP 會跳出驗證框)
※ 目錄下所有檔案皆需增加此權限,特別是php5isapi.dll)
※ 於IIS下建立虛擬站台時,該站台下所有程式檔案亦需執行步驟3,加入權限方可正常使用。

4. 加入系統環境變數 (讓 extension 及 php.ini 能順利被找到)。
我的電腦按右鍵→內容→進階→環境變數:系統變數

Path=C:\PHP5;
PHPRC=C:\PHP5

5. 開啟 IIS 管理員。

5.1 根目錄網站按右鍵→主目錄:設定→對應:快取處理ISAPI擴充程式:新增
5.2 執行檔:C:\PHP5\php5isapi.dll
副檔名:.php
指令動詞:限於為:GET,HEAD,POST
勾選 指令碼引擎,不勾選 確認該檔案是否存在
5.3 確定

6. 增加預設首頁 index.php
文件tab→新增:index.php→確定

7. 增加網頁服務延伸。
IIS:點選「網頁服務延伸」→新增網頁服務延伸:

7.1 延伸名稱:PHP ISAPI
7.2 需要的檔案:新增→C:\PHP5\php5isapi.dll
7.3 勾選 設定延伸狀態成允許
7.4 確定

8. 重新啟動 IIS 就 OK 囉~(非僅重新啟動WEB站台!)

※ php出現「No input file specified.」訊息時,將php.ini的doc_root註解起來,
再重新啟動IIS即可

※ postgreSQL: php_pgsql.dll要打開,僅適用於php5.2.5以下,
再不行就增加postgresql\bin目錄至"系統變數"
(參考: http://sea.tokyo.idv.tw/?p=76)

2009年6月11日

[PHP]讀取JPEG圖檔dpi

讀取JPEG圖檔dpi

function get_dpi($filename){

// open the file and read first 20 bytes.
$a = fopen($filename,'r');
$string = fread($a,20);
fclose($a);

// get the value of byte 14th up to 18th
$data = bin2hex(substr($string,14,4));
$x = substr($data,0,4);
$y = substr($data,4,4);
/* $x,$y: 01 2C = 300dpi ; 00 48 = 72dpi */
return array(hexdec($x),hexdec($y));

}

程式出處: http://sandalian.com/php/get-dpi-value-of-an-image-using-php.html
JPEG結構說明: http://bytes.com/groups/php/5948-dpi-php-gd
JPEG結構&DPI說明: http://apptools.com/examples/dpi.php

2009年3月21日

[php]將Unicode轉換為Big5,缺字以&#xxxxx編碼顯示

將UTF-16 or UTF-8 轉換為Big5,無法轉換的字以 &#xxxxx 的編碼代替(參考網路文章測試後再修改之~):
* php 需安裝 mbstring模組: php_mbstring.dll

//轉換編碼時無法轉換的字元,設定應用何種方式顯示(預設: ?、none: 無、long: U+xxx)
mb_substitute_character("long");
$file_cont=convertUnicodeNotation(mb_convert_encoding($file_cont, 'BIG5', 'UCS-2LE'));
//echo convertUnicodeNotation(mb_convert_encoding($data, 'BIG-5', 'UTF-8'));

//將 U+79C3 之類的編碼,轉換為&#xxxxx => '&#'.intval('79C3',16)
function convertUnicodeNotation($str) {
if (eregi('U\+([0-9A-F]{4})',$str,$regs))
{ return convertUnicodeNotation(str_replace($regs[0], '&#'.intval($regs[1],16).';', $str));
}
return $str;
}