<tfoot id='oBOSp'></tfoot>
    1. <legend id='oBOSp'><style id='oBOSp'><dir id='oBOSp'><q id='oBOSp'></q></dir></style></legend>

      <small id='oBOSp'></small><noframes id='oBOSp'>

      <i id='oBOSp'><tr id='oBOSp'><dt id='oBOSp'><q id='oBOSp'><span id='oBOSp'><b id='oBOSp'><form id='oBOSp'><ins id='oBOSp'></ins><ul id='oBOSp'></ul><sub id='oBOSp'></sub></form><legend id='oBOSp'></legend><bdo id='oBOSp'><pre id='oBOSp'><center id='oBOSp'></center></pre></bdo></b><th id='oBOSp'></th></span></q></dt></tr></i><div id='oBOSp'><tfoot id='oBOSp'></tfoot><dl id='oBOSp'><fieldset id='oBOSp'></fieldset></dl></div>

      • <bdo id='oBOSp'></bdo><ul id='oBOSp'></ul>

      使用 scandir() 在目录中查找文件夹 (PHP)

      时间:2023-07-15
        <bdo id='kkJVY'></bdo><ul id='kkJVY'></ul>
        • <legend id='kkJVY'><style id='kkJVY'><dir id='kkJVY'><q id='kkJVY'></q></dir></style></legend>
        • <small id='kkJVY'></small><noframes id='kkJVY'>

              <tbody id='kkJVY'></tbody>
            • <tfoot id='kkJVY'></tfoot>

                <i id='kkJVY'><tr id='kkJVY'><dt id='kkJVY'><q id='kkJVY'><span id='kkJVY'><b id='kkJVY'><form id='kkJVY'><ins id='kkJVY'></ins><ul id='kkJVY'></ul><sub id='kkJVY'></sub></form><legend id='kkJVY'></legend><bdo id='kkJVY'><pre id='kkJVY'><center id='kkJVY'></center></pre></bdo></b><th id='kkJVY'></th></span></q></dt></tr></i><div id='kkJVY'><tfoot id='kkJVY'></tfoot><dl id='kkJVY'><fieldset id='kkJVY'></fieldset></dl></div>
                本文介绍了使用 scandir() 在目录中查找文件夹 (PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用这段代码:

                $target = 'extracted/' .$名称[0];$scan = scandir($target);

                扫描用于 zip 上传的文件夹的目录.我希望能够在我的 $target 文件夹中找到所有文件夹,以便我可以删除它们及其内容,只留下 $target 目录中的文件.

                一旦我返回了文件夹的内容,我不知道如何区分文件夹和文件才能删除文件夹.

                另外,我被告知 rmdir() 函数无法删除其中包含内容的文件夹,有什么办法可以解决这个问题吗?

                谢谢,本.

                解决方案

                使用is_dir()is_file() 函数确定你是否有文件夹或文件代码>

                例如:

                <前>$path = '提取/' .$名称[0];$results = scandir($path);foreach ($results as $result) {if ($result === '.' or $result === '..') continue;if (is_dir($path . '/' . $result)) {//如果目录使用的代码}}

                I am using this peice of code:

                $target = 'extracted/' . $name[0];  
                $scan = scandir($target);
                

                To scan the directory of a folder which is used for zip uploads. I want to be able to find all the folders inside my $target folder so I can delete them and their contents, leaving only the files in the $target directory.

                Once I have returned the contents of the folder, I don't know how to differentiate between the folders and the files to be able to delete the folders.

                Also, I have been told that the rmdir() function can't delete folders which have content inside them, is there any way around this?

                Thanks, Ben.

                解决方案

                To determine whether or not you have a folder or file use the functions is_dir() and is_file()

                For example:

                $path = 'extracted/' . $name[0];
                $results = scandir($path);
                
                foreach ($results as $result) {
                    if ($result === '.' or $result === '..') continue;
                
                    if (is_dir($path . '/' . $result)) {
                        //code to use if directory
                    }
                }
                

                这篇关于使用 scandir() 在目录中查找文件夹 (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:来自远程服务器的 PHP 目录列表 下一篇:如何删除非空目录?

                相关文章

                • <bdo id='WgTur'></bdo><ul id='WgTur'></ul>

                  <tfoot id='WgTur'></tfoot>

                1. <legend id='WgTur'><style id='WgTur'><dir id='WgTur'><q id='WgTur'></q></dir></style></legend>
                  <i id='WgTur'><tr id='WgTur'><dt id='WgTur'><q id='WgTur'><span id='WgTur'><b id='WgTur'><form id='WgTur'><ins id='WgTur'></ins><ul id='WgTur'></ul><sub id='WgTur'></sub></form><legend id='WgTur'></legend><bdo id='WgTur'><pre id='WgTur'><center id='WgTur'></center></pre></bdo></b><th id='WgTur'></th></span></q></dt></tr></i><div id='WgTur'><tfoot id='WgTur'></tfoot><dl id='WgTur'><fieldset id='WgTur'></fieldset></dl></div>
                  1. <small id='WgTur'></small><noframes id='WgTur'>