Maison > développement back-end > tutoriel php > PHP中确定目录大小的相关问题代码

PHP中确定目录大小的相关问题代码

WBOY
Libérer: 2016-07-29 08:59:01
original
916 Les gens l'ont consulté

<code><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><?php function directory_size<span>(<span>$address</span>)</span>  //address传入文件路径
    {
        <span>$size</span>=<span>0</span>;//初始化文件大小变量
        if<span>(<span>$dir</span>=@opendir<span>(<span>$address</span>)</span>)</span>  //如果正常打开文件则进行下一步操作
        {
            while<span>(<span>$filename</span>=readdir<span>(<span>$dir</span>)</span>)</span>
            {
                if<span>(<span>$filename</span>!=<span>"."</span>&&<span>$filename</span>!=<span>".."</span>)</span>
                {
                    if<span>(is_file<span>(<span>$address</span>.<span>"\\"</span>.<span>$filename</span>)</span>)</span>
                    {
                        <span>$size</span>+=filesize<span>(<span>$address</span>.<span>"\\"</span>.<span>$filename</span>)</span>;
                    }
                    if<span>(is_dir<span>(<span>$address</span>.<span>"\\"</span>.<span>$filename</span>)</span>)</span>                    {
                        <span>$size</span>+=directory_size<span>(<span>$address</span>.<span>"\\"</span>.<span>$filename</span>)</span>;
                    }
                }
            }
        }
        @closedir<span>(<span>$dir</span>)</span>;
        return <span>$size</span>;
    }

    <span>$dire_address</span>=<span>"F:\course"</span>;
    <span>$totalsize</span>=directory_size<span>(<span>$dire_address</span>)</span>;
    printf<span>(<span>"%s"</span>,<span>$totalsize</span>)</span>;


?></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>
Copier après la connexion

说明@:通过在函数名前加上 “@” 来隐藏 error 的输出
opdendir:打开目录句柄
readdir:返回由 opendir() 打开的目录句柄中的条目
is_file:判断是否是文件
is_dir:判断是否是目录

实验环境:windows 10操作系统
Eclipse for PHP Developers(Mars)
WampServer Version2.4

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP中确定目录大小的相关问题代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal