首页 >后端开发 >php教程 >php无限遍历目录-修正版_PHP教程

php无限遍历目录-修正版_PHP教程

WBOY
WBOY原创
2016-07-13 10:36:31788浏览

改变为指定的目录。

opendir() 打开目录。

readdir()读取目录。

getcwd()。获取当前目录。

还用到了for  if  GET传值 大概就这些东东:

下面是代码:




<span <?<span php
</span><span if</span>(<span isset</span>(<span $_GET</span>['id']))<span //</span><span 判断是否传值</span>
<span {
    </span><span $s</span>=<span str_replace</span>(' ','+',<span $_GET</span>['id'<span ]);
    </span><span $s</span>=<span base64_decode</span>(<span $s</span>);<span //</span><span 接受传递的值 值一般是要打开的目录的绝对路劲</span>
        <span chdir</span>(<span $s</span>);<span //</span><span 切换到要打开的目录</span>
<span     }
</span><span $a</span>=<span opendir</span>('.');<span //</span><span 打开当前目录</span>
<span while</span>(false!==(<span $c</span>=<span readdir</span>(<span $a</span>)))<span //</span><span 循环遍历目录内容的文件名</span>
<span {         
       </span><span if</span>(<span is_dir</span>(<span $c</span>))<span //</span><span 判断是目录还是文件</span>
<span        {
           </span><span if</span>(<span $c</span>=='.'<span )
           {
               }
               </span><span else</span><span 
               {
           </span><span if</span>(<span $c</span>=='..'<span )
           {
           </span><span $w</span>=<span base64_encode</span>(<span substr</span>(<span getcwd</span>(),0,<span strrpos</span>(<span getcwd</span>(),'\\')));<span //</span><span 当前路径加上目录名 就是目录的绝对路径</span>
           <span echo</span> "上一级"."<a href='6.php?id=<span $w</span>'>打开</a><br />";<span //</span><span 当点击打开时将要打开的绝对路径传递出去  用chdir 切换到要打开的目录下</span>
           }<span else</span><span 
           {
               </span><span $w</span>=<span base64_encode</span>(<span getcwd</span>().'\\'.<span $c</span>);<span //</span><span 当前路径加上目录名 就是目录的绝对路径</span>
           <span echo</span> "<span $c</span>"."<a href='6.php?id=<span $w</span>'>打开</a><br />";<span //</span><span 当点击打开时将要打开的绝对路径传递出去  用chdir 切换到要打开的目录下</span>
<span                }
               }
           }
           </span><span else</span><span 
           {
               </span><span echo</span> "<span $c</span> 不是目录<br />"<span ;
               }
}

</span>?></span>

 

<span  </span>

大家如果有什么建议可以提出来!!谢谢!!

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/738554.htmlTechArticle改变为指定的目录。 opendir() 打开目录。 readdir()读取目录。 getcwd()。获取当前目录。 还用到了for if GET传值 大概就这些东东: 下面是...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn