<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_35131"> <img alt="PHP計算一個資料夾的大小" src="http://img.it-home.org/data/attachment/forum/2014pic/16195715_kPci.png"> http://blog.1dnet.net/?post=839 <div class="blockcode"> <div id="code_xyg"><ol> <li> <?php <li>//http://blog.1dnet.net</li> <li> function dirSize($directoty){</li> <li> $dir_size=0;</li> <li> <li> if($dir_handle=@opendir($directoty))</li> <li> {</li> <li> while($filename=readdir($dir_handle)){</li> <li> $subFile=$directoty.DIRECTORY_SEPARATOR.$filename;</li> <li> if($filename=='.'||$filename=='..'){</li> <li> continue;</li> <li> }elseif (is_dir($subFile))</li> <li> {</li> <li> $dir_size+=dirSize($subFile);</li> <li> }elseif (is_file($subFile)){</li> <li> $dir_size+=filesize($subFile);</li> <li> }</li> <li> }</li> <li> closedir($dir_handle);</li> <li> }</li> <li> return ($dir_size);</li> <li> }</li> <li> <li> $dir_size=dirSize("xym");</li> <li> echo round($dir_size/pow(1024,1),2)."KB";</li> <li>?></li> </ol></div> <em onclick="copycode($('code_xyg'));">复制代码</em> </div> </td></tr></table> <div id="comment_35131" class="cm"> </div> <div id="post_rate_div_35131"></div> <br><br>