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