Folder problem

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-15 11:30:59901browse

Folder problem

Folder problem

Why is there only one folder a echoed when there are several folders? And there are three dots in front of a. Why is this?

<code>    $dir = "upload/"; 
    if (is_dir($dir)){
        if ($dh = opendir($dir)){
        while (($file = readdir($dh))!= false){
            if(is_dir($file)) {
              echo $file;
            }
        }
        closedir($dh);
        }
    }</code>

Reply content:

Folder problem

Folder problem

Why is there only one folder a echoed when there are several folders? And there are three dots in front of a. Why is this?

<code>    $dir = "upload/"; 
    if (is_dir($dir)){
        if ($dh = opendir($dir)){
        while (($file = readdir($dh))!= false){
            if(is_dir($file)) {
              echo $file;
            }
        }
        closedir($dh);
        }
    }</code>

The usage of

is_dir($file) is incorrect.

Maybe you want to traverse e:/www/project/public/upload, but $dir = "upload" may not be the address you want. Generally, this is done in combination with magic variables. For example

<code>$base = __DIR__;
$dir = $base . '/upload';
echo $dir; //看看是不是这个目录
// if (is_dir($dir)) <- 这个判断没用,你自己要求遍历upload的,还检查一遍,不相信自己?如果要处理的话也应该这样做
if (! is_dir($dir)) {
    //创建这个目录
}
$dh = opendir($dir);
while($file = readdir($dh)) {
    if ($file === '.' || $file === '..') continue; //理由自己搜索,太基础了
    if (is_dir($dir . '/' . $file)) { //要使用完整路径
        echo $file;
    }
}</code>

It is recommended to read more of the PHP manual, rather than the book or video, or the order. You should read the manual first and then the book or video. There are standard examples of this in the manual.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn