2009年10月23日 星期五

[PHP] 解壓縮 ZIP 檔案

因為專案需要利用 PHP 解壓縮 ZIP 檔案,解析裡面的內容
咕狗了一下,發現有一個套件還滿好用的

PclZip (目前版本至 2.8,2,持續更新中..)
還是來做個筆記記錄一下吧!


使用方法 :
1.include 至檔案中,如: include_once( 'pclzip.lib.php');
2.解壓縮目錄記得將寫入權限開啟,如: temp目錄設定為 777

基本用法 :
//view plaincopy to clipboardprint?
require_once('pclzip.lib.php'); 
$archive = new PclZip('archive.zip'); 
$archive->extract(); 

這樣就完成最基本的解壓縮功能,還有其他參數可以設定,見下表

參數
引數
說明
PCLZIP_OPT_PATH
字串
要解壓縮到哪的路徑。可用於extract()、extractByIndex()。

PCLZIP_OPT_ADD_PATH
字串
增加一個目錄。可用於create()、add()、extract()。(使用於create()時,是把要壓縮的檔案放進這個目錄中再壓縮,使用於extract()時,是在要解壓縮的路徑中增加此目錄,並解壓縮到此目錄中)。

PCLZIP_OPT_REMOVE_PATH
字串
移除部份的目錄路徑,例如原本檔案所在的目錄為aa/bb/cc/test.test.txt,但是希望壓縮或解壓縮後的路徑為cc/test.txt, 就可以使用PCLZIP_OPT_REMOVE_PATH,"aa/bb"。可用於create()、add()、extract()、 extractByIndex()。(與PCLZIP_OPT_REMOVE_ALL_PATH一起用的時候會被自動忽略)

PCLZIP_OPT_REMOVE_ALL_PATH
--
移除所有檔案的目錄,所有檔案都會被解壓縮或壓縮到當前或是指定的目錄中,請注意如果有不同目錄的相同名稱檔案,使用此參數時會被覆蓋,此參數不需要引數。可用於create()、add()、extract()、extractByIndex()。

PCLZIP_OPT_SET_CHMOD
CHMOD值
設定解壓縮出來的檔案的CHMOD值。可用於extract()、extractByIndex()。

PCLZIP_OPT_BY_NAME
檔案名稱
僅解壓縮引數中所指定的檔案,檔案名稱可以用陣列或是逗號隔開表示。

PCLZIP_OPT_BY_EREG
RegEx字串
僅解壓縮引數中正規表達式比對檔名正確的檔案,使用php中的ereg()函式比對。

PCLZIP_OPT_BY_PREG
RegEx字串
僅解壓縮引數中正規表達式比對檔名正確的檔案,使用php中的preg_match()函式比對。

PCLZIP_OPT_BY_INDEX
陣列
僅解壓縮引數陣列中各元素所指定順序的檔案。(這個我還不太懂是照什麼順序,似乎不是照字母排)

PCLZIP_OPT_EXTRACT_AS_STRING
--
將一個檔案的內容解壓縮成一個字串,通常可能用於只需要看readme檔案的情況。請注意如果一次解壓縮太多檔案,有可能會將記憶體耗盡。

PCLZIP_OPT_EXTRACT_IN_OUTPUT
--
將一個檔案的內容解壓縮並直接輸出(即類似直接echo此結果)。

PCLZIP_OPT_NO_COMPRESSION
--
將一個檔案加入此壓縮檔內,此檔案不會被壓縮,僅是放入同一個壓縮檔中。

PCLZIP_OPT_COMMENT
字串
建立壓縮檔時增加一個註解,如果原本已經有註解的話,將會直接覆蓋過去。

PCLZIP_OPT_ADD_COMMENT
字串
建立壓縮檔時增加一個註解,如果原本已經有註解的話,將會接在後面。

PCLZIP_OPT_PREPEND_COMMENT
字串
建立壓縮檔時增加一個註解,如果原本已經有註解的話,將會把原先的註解接在此字串的後面。



資料參考來源:
http://itisjoe.pixnet.net/blog/post/14758894
http://support.oss.org.tw/?q=node/147

2009年10月21日 星期三

[工具] 產生 Loading 圖示的網站

剛好看到別人的部落格分享,就隨手記錄一下吧!
工作上正好需要,就不用一直麻煩視覺處理了
其中 Load Info 已經用過一陣子了,效果還不錯,符合大多數的需求
而 Preloaders 剛試玩了一下,提供的樣式明顯多了很多

[CKFinder] 1.3.2 破解方法筆記

CKFinder 在允許你免費使用的同時,視窗始終有一個“This is the demo version of CKFinder. Click here to visit our web site.”的提示。這種情況一般是顯示一個DIV層或table,取消的辦法無非是隱藏或不讓這段內容添加到物件上即可。

經過分析發現 ckffiles.html 中 “” 有很多嫌疑,基本可以確定是放上面那句話的容器,對 ckfinder_ie.js 分析,有鎖定下面代碼 var D=B.createElement('iframe');D.src=bJ;D.frameBorder=0;D.width=D.height='100%';en.call(window,'\x76\x61\162\40\145\106\73');eF=B.getElementById('qu');if ((1==(dK.indexOf(ab.bW.substr(1,1)) % 5)&&window.top[qC+'\143\141\x74\x69\157\x6E'][qF+'\163\x74'].toLowerCase()!=ab.eo)||ab.bW.substr(3,1)!=dK.substr(((dK.indexOf(ab.bW.substr(0,1))+dK.indexOf(ab.bW.substr(2,1)))*9) % (dK.length-1),1)){/*en.call(window,qo);*/};eF.appendChild(D); 我們只需要把紅色部分注釋掉就OK!

文章來源:
http://jiahf.spaces.live.com/blog/cns!52FB5204951A6E9A!453.entry

[jQuery] 幾個不錯的 Plugins (彈出視窗)

對於 colorbox 和 fancybox 這兩者的印象比較好,找個時間再試用套在專案上吧!

2009年10月18日 星期日

[SVN] 執行更新或加入遠端目錄時遇到的問題

錯誤訊息:
org.tigris subversion javahl.ClientException: Working copy not locked;this is probably a bug,please report
svn:Working copy '你的專案目錄' is missing or not locked
原因是eclipse把src資料夾中的.svn資料夾也"編譯"到WEB-INF/classes中去了,而複製過來的.svn中存儲的是src資料夾中的版本資訊,從而導致在更新時出錯。

解決方法:
打開 Eclipse 中的 Project->Properties->Java Build Path 功能表,在右側面板中的"Source"選項卡,在Excluded中加入"**/.svn/**"。
也就是把.svn資料夾從編譯路徑中排除,這樣就不會出現上面的問題了。

---------------------------------------------------------
錯誤訊息:
containing working copy admin area is missing
表示該目錄下 .svn 受損。

解決方法 1:
1. 先將該目錄檔案另外備份 (不含 .svn 底下的東西)
2. 將該目錄以及底下檔案全部刪除
3. svn update
4. 將剛剛備份的資料還原上去

解決方法 2:
1. Click to Team->Clean Up
2. Try again to commit..

2009年10月16日 星期五

[Javascript] 編碼設定

如果 web application 的編碼規則是 utf-8,如網頁頭中的:

<meta http-equiv="Content-Type" content="text/html; charset="utf-8" />

那麼 js 檔中如果有中文輸出就會出現亂碼,解決此個問題可在引用javascript輸出的地方加上charset="utf-8" 或 charset="big5"(假設輸出的是 UTF-8 編碼)。

例:
<script type="text/javascript" language="javascript" src="scripts/output.js" charset="utf-8"></script>

注意:
對應的 js 文件檔案編碼也要儲存成符合設定的編碼語系,如範例為 utf-8 編碼

文章來源:
http://www.cnblogs.com/zgqys1980/archive/2007/11/13/957653.html

2009年10月8日 星期四

[Codeigniter] Codeigniter 整合 AmfPHP

Codeigniter  搭配開發 FLEX 專案時,要如何透過 Amfphp 傳送資料至前端 FLEX 處理呢?
整合步驟如下:

所需套件:
1. Codeigniter 1.7.1 版本以上
2. AMFPHP 1.9 版本以上

整合流程:
1. 先將解壓縮後的 amfphp 資料夾移至 Codeigniter 開發目錄 (預設路徑為 system\application\) 下的 libraries 目錄裡
2. 建立 amfphp gateway controller 檔案  ( amf_gateway.php )

//This file replaces the need for gateway.php
//setup netConnection to ‘/index.php/amf_gateway’
class Amf_gateway extends Controller
{
  public function __construct()
  {
    parent::Controller();
    //Start our library (keep reading the tutorial)
    $this->load->library('amfci');
    //Set new include path for services
    ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . AMFSERVICES);
  }

//startup the amf gateway service
public function index()
 {
  $this->amfci->service();
 }
} 

3. 建立 amfci_db 檔案至 libraries/amfphp/services/ 目錄下

require_once(BASEPATH.'/../system/libraries/Model.php');


4. 建立 amfci class 檔案至 libraries 目錄下


//This file is the new amfphp library for CI
//It it loaded from the amf_gateway controller, and binds all of it together
class Amfci
{
  public $gateway;
  public $CI;
  public function __construct()
  {
    $this->CI = get_instance();
    require realpath(dirname(__FILE__))."/amfphp/globals.php";
    require realpath(dirname(__FILE__))."/amfphp/core/amf/app/Gateway.php";
    define('AMFSERVICES', realpath(dirname(__FILE__))."/amfphp/services");

    $this->gateway = new Gateway();
    $this->gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
    $this->gateway->setLooseMode();
    $this->gateway->setErrorHandling(E_ALL ^ E_NOTICE);
    $this->gateway->setClassMappingsPath(AMFSERVICES.'/vo');
    $this->gateway->setClassPath(AMFSERVICES);

    if(PRODUCTION_SERVER)
    {
      //Disable profiling, remote tracing, and service browser
      $this->gateway->disableDebug();
    }
  }

  public function service()
  {
    $this->gateway->service();
  }
}
 
5.完成以上四個步驟後,基本的 amfphp 整合已大致完成,接下來就是對應前端的 Service 開發過程
 1.首先在 libraries\amfphp\services 下建立 amfphp Service 
2.載入所需的 model class
3.透過 service 繼承 model 取用存取後端資料方法

require_once('amfci_db.php');

// Use this path if you are using a module (ie, MatchBox)
// require_once(AMFSERVICES.'/../../../modules/test_shop/models/product_model.php');
require_once(AMFSERVICES.'/../../../models/product_model.php');
class product_service extends Product_model
{

}
 
6.最後建立 Flex 專案利用 RemoteObject 建立 amfphp gateway 取用 Service