php 怎样读取指定目录下面的所有文件?

WBOY
发布: 2016-08-08 09:22:45
原创
1239 人浏览过

<code><span><span>function</span><span>treeDirectory</span><span>(<span>$dir</span>)</span>{</span><span>$files</span> = <span>array</span>();
    <span>$dirpath</span> = realpath(<span>$dir</span>);
    <span>$filenames</span> = scandir(<span>$dir</span>);

    <span>foreach</span> (<span>$filenames</span><span>as</span><span>$filename</span>) 
    {
        <span>if</span> (<span>$filename</span>==<span>'.'</span> || <span>$filename</span>==<span>'..'</span>)
        {
            <span>continue</span>;
        }

        <span>$file</span> = <span>$dirpath</span> . DIRECTORY_SEPARATOR . <span>$filename</span>;

        <span>if</span> (is_dir(<span>$file</span>))
        {
            <span>$files</span> = array_merge(<span>$files</span>, <span>self</span>::treeDirectory(<span>$file</span>));
        }
        <span>else</span>
        {
            <span>$files</span>[] = <span>$file</span>;
        }
    }

    <span>return</span><span>$files</span>;
}</code>
登录后复制

以上就介绍了php 怎样读取指定目录下面的所有文件?,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板