2009年4月10日

【PHP+JS+Flash】檔案上傳的好幫手 - FancyUpload

官方網站:


http://digitarald.de/project/fancyupload/





這兩天使用時





突然發現會出現error





上官網看了一下





原來是Flash Player 10在搞鬼


(參考這篇:http://digitarald.de/journal/54706744/fancyupload-for-flash-10/





經過更新後又可以使用了





不過新版本好像有些許bug





就等待作者更新了

2009年3月28日

【PHP】filesize Fix 4Gb limit.

只能說被騙了~"~



還以為某檔案壞掉



檔案大小一直抓不正確



原來是php裡的filesize function 只支援到4 Gb.....





Fix 4Gb limit. ( Now limit 8 Gb ;))



<?php

   
function GetRealSize($file) {

       
// Return size in Mb

       
clearstatcache();

       
$INT = 4294967295;//2147483647+2147483647+1;

       
$size = filesize($file);

       
$fp = fopen($file, 'r');

       
fseek($fp, 0, SEEK_END);

        if (
ftell($fp)==0) $size += $INT;

       
fclose($file);

        if (
$size<0) $size += $INT;

        return
ceil($size/1024/1024);

    }

?>

【PHP】PHP 中的 unescape 函式

   function phpescape($str){

    
$sublen=strlen($str);

    
$reString="";

    
for ($i=0;$i<$sublen;$i++){

        
if(ord($str[$i])>=127){

            
$tmpString=bin2hex(iconv("utf-8","ucs-2",substr($str,$i,2)));    



            
if (!eregi("WIN",PHP_OS)){

                
$tmpString=substr($tmpString,2,2).substr($tmpString,0,2);

            }

            
$reString.="%u".$tmpString;

            
$i++;

        } 
else {

            
$reString.="%".dechex(ord($str[$i]));

        }

    }

    
return $reString;

}





function unescape($str) { 

         
$str = rawurldecode($str); 

         
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r); 

         
$ar = $r[0]; 

         
foreach($ar as $k=>$v) { 

                  
if(substr($v,0,2== "%u"

                           
$ar[$k= iconv("UCS-2","utf-8",pack("H4",substr($v,-4))); 

                  
elseif(substr($v,0,3== "&#x"

                           
$ar[$k= iconv("UCS-2","utf-8",pack("H4",substr($v,3,-1))); 

                  
elseif(substr($v,0,2== "&#") { 

                           
$ar[$k= iconv("UCS-2","utf-8",pack("n",substr($v,2,-1))); 

                  } 

         } 

         
return join("",$ar); 









轉貼至:

http://www.phpchina.com/html/91/n-1091.html

2009年2月23日

【ExtJS】Grid 資料可用拖拉方式交換

var ddrow = new Ext.dd.DropTarget(Grid.getView().mainBody, {

            ddGroup : 'ddGroup',

            copy:false,

            notifyDrop : function(ddSource, e, data){

               

                var sm = Grid.getSelectionModel();

                var rows = sm.getSelections();

                var cindex = ddSource.getDragData(e).rowIndex;

                if (!this.copy){

                    for(i = 0; i < rows.length; i++) {

                        ds.remove(ds.getById(rows[i].id));

                    };

                };

                ds.insert(cindex,data.selections);

    

            }

});



grid 別忘了將 enableDragDrop設為true

2009年1月7日

【Javascript】Sleep

function   sleep(n)  {
          var   start=new   Date().getTime();
          while(true)
                 if(new   Date().getTime()-start>n)
                       break;
}





累了就要睡~~@@

2008年12月23日

Setting the HTTP charset parameter

因為太常用到了





所以轉貼至我的網誌





方便日後查詢





以下節錄自:


http://www.w3.org/International/O-HTTP-charset





只紀錄Code部份










<h2>Scripting the header</h2>

The appropriate header can also be set in server side scripting languages. For example:



Perl. Output the correct header before any part of the actual page. After the last header, use a double linebreak, e.g.:


print "Content-Type: text/html; charset=utf-8\n\n";



Python. Use the same solution as for Perl (except that you don't need a semicolon at the end).



PHP. Use the header() function before generating any content, e.g.:


header('Content-type: text/html; charset=utf-8');



Java Servlets. Use the setContentType method on the ServletResponse before obtaining any object (Stream or Writer) used for output, e.g.:


resource.setContentType ("text/html;charset=utf-8");


If you use a Writer, the Servlet automatically takes care of the conversion from Java Strings to the encoding selected.



JSP. Use the page directive e.g.:


<%@ page contentType="text/html; charset=UTF-8" %>


Output from out.println() or the expression elements (<%= object%>) is automatically converted to the encoding selected. Also, the page itself is interpreted as being in this encoding.



ASP and ASP.Net. content type and charset are set independently, and are methods on the response object. To set the charset, use e.g.:


<%Response.charset="utf-8"%>


In ASP.Net, setting Response.ContentEncoding will take care both of the charset parameter in the HTTP Content-Type as well as of the actual encoding of the document sent out (which of course have to be the same). The default can be set in the globalization element in Web.config (or Machine.config, which is originally set to UTF-8).



2008年12月1日

【ExtJS】Ajax Communication failure 解決方法

只需在Ajax failure function 內加入







failure: function(obj1,obj2) {



               if(obj1.statusText == 'communication failure') {



                    var task = new Ext.util.DelayedTask(/*你的ajax code or function*/);



                    task.delay(1);



                }else{



                    alert('請告知管理員伺服器有 : '+obj1.statusText+' 的錯誤');



                }



}



或檢查呼叫的php有無不會顯示訊息的執行錯誤

例如:無限遞迴