<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="PHP遍历一层目录并返回统计目录大小的示例代码" id="card1">
<p> 游客</p><p>
标题:PHP遍历一层目录并返回统计目录大小的示例代码<br/>
正文:<br/>
代码如下:&amp;lt;?php <br/>$dirname = &quot;test1&quot;; <br/>//mkdir($dirname); <br/><br/>//遍历一层目录 <br/>function listdir($dirname) { <br/>    $ds = opendir($dirname); <br/>    while($file = readdir($ds)) { <br/>        $path = $dirname.'/'.$file; <br/>        if(is_dir($file)) { <br/>            echo &quot;DIR:&quot;.$file.&quot;&amp;lt;br&amp;gt;&quot;; <br/>            if($file != &quot;.&quot; &amp;amp;&amp;amp; $file != &quot;..&quot;) { <br/>                listdir($file); <br/>            } <br/>        }else { <br/>           echo &quot;FILE:&quot;.$file . &quot;&amp;lt;br&amp;gt;&quot;; <br/>        } <br/>    } <br/>} <br/><br/>function totdir($dirname) { //对listdir稍加修改 <br/>    static $tot = 0; <br/>    $ds = opendir($dirname); <br/>    while($file = readdir($ds)) { <br/>        $path = $dirname.'/'.$file; <br/>        if(is_dir($file)) { <br/>            //echo &quot;DIR:&quot;.$file.&quot;&amp;lt;br&amp;gt;&quot;; <br/>            if($file != &quot;.&quot; &amp;amp;&amp;amp; $file != &quot;..&quot;) { <br/>                $tot += totdir($file); <br/>            } <br/>        }else { <br/>            //echo &quot;FILE:&quot;.$file . &quot;&amp;lt<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1663&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1663&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1663&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1663&amp;Page=2">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=1663">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=1663">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>