Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用readdir时返回空字符串_Php - Fatal编程技术网

Php 使用readdir时返回空字符串

Php 使用readdir时返回空字符串,php,Php,我在下面的代码中使用readdir来获取目录中所有图像文件名的列表 while (false !== ($entry = readdir($frameDir))){ $shapeName = explode('.',$entry); if (!empty($shapeName[0]) && $shapeName[0] != '.' && $shapeName[0] != '..' && $shapeName[0] != '/

我在下面的代码中使用readdir来获取目录中所有图像文件名的列表

while (false !== ($entry = readdir($frameDir))){
    $shapeName = explode('.',$entry);
    if (!empty($shapeName[0]) && $shapeName[0] != '.' && $shapeName[0] != '..' &&     $shapeName[0] != '/'){
        $shapeName = $shapeName[0];
        $shapes['frames'][] = $shapeName;
    }
在这段代码之后,脚本会附加“.png”以使其成为有效的文件名

如您所见,我已尝试消除传递空白文件名的任何可能性。不过,当我运行脚本时,最终得到一个空白目录“/shapes/frame/.png”。这只会发生在这个特定的目录中。当我在三个目录中的另一个目录上使用代码时,我得到了预期的结果,代码的逻辑与上面使用的相同

while (false !== ($entry = readdir($frameDotDir))){
    $shapeName = explode('.',$entry);
    if (!empty($shapeName[0]) && $shapeName[0] != '.' && $shapeName[0] != '..' &&     $shapeName[0] != '/'){
        $shapeName = $shapeName[0];
        $shapes['frame_dots'][] = $entry;
    }
}
在服务器上检查文件系统时,我找不到任何名称为空的文件


我想知道是什么原因导致我的脚本从目录中读取空白文件名。

文件名不能为空(也不会为空)。您的代码中有错误。它应该是这样的:

while ($entry = readdir($frameDir)){
    // skip files which names starting with a dot
    // like '.', '..' or hidden files
    if (strpos($entry, '.') !== 0) {
        $shapes['frame_dots'][] = $entry;
    }
}

你看,少就是多;)

文件名不能为空(也不会为空)。您的代码中有错误。它应该是这样的:

while ($entry = readdir($frameDir)){
    // skip files which names starting with a dot
    // like '.', '..' or hidden files
    if (strpos($entry, '.') !== 0) {
        $shapes['frame_dots'][] = $entry;
    }
}

你看,少就是多;)

文件名不能为空(也不会为空)。您的代码中有错误。它应该是这样的:

while ($entry = readdir($frameDir)){
    // skip files which names starting with a dot
    // like '.', '..' or hidden files
    if (strpos($entry, '.') !== 0) {
        $shapes['frame_dots'][] = $entry;
    }
}

你看,少就是多;)

文件名不能为空(也不会为空)。您的代码中有错误。它应该是这样的:

while ($entry = readdir($frameDir)){
    // skip files which names starting with a dot
    // like '.', '..' or hidden files
    if (strpos($entry, '.') !== 0) {
        $shapes['frame_dots'][] = $entry;
    }
}
你看,少就是多;)

为什么不使用而不是
readdir()
。只要给它一个模式,它就可以让您轻松地处理文件名,而不是逐个扫描。在您的情况下,它不可能返回空文件名。另外,看看文档中的
glob
标志,您会惊讶于它的简单性

glob("*.png");
输出:

Array ( [0] => shape.png, [1] => shape2.png )
为什么不使用而不是
readdir()
。只要给它一个模式,它就可以让您轻松地处理文件名,而不是逐个扫描。在您的情况下,它不可能返回空文件名。另外,看看文档中的
glob
标志,您会惊讶于它的简单性

glob("*.png");
输出:

Array ( [0] => shape.png, [1] => shape2.png )
为什么不使用而不是
readdir()
。只要给它一个模式,它就可以让您轻松地处理文件名,而不是逐个扫描。在您的情况下,它不可能返回空文件名。另外,看看文档中的
glob
标志,您会惊讶于它的简单性

glob("*.png");
输出:

Array ( [0] => shape.png, [1] => shape2.png )
为什么不使用而不是
readdir()
。只要给它一个模式,它就可以让您轻松地处理文件名,而不是逐个扫描。在您的情况下,它不可能返回空文件名。另外,看看文档中的
glob
标志,您会惊讶于它的简单性

glob("*.png");
输出:

Array ( [0] => shape.png, [1] => shape2.png )

我在使用readdir()时遇到了与空白文件名相同的问题,结果是目录名错误,linux是区分大小写的,在代码中,目录名以“I”开头,在linux中,目录以“I”开头


我猜这个错误是由于没有处理opendir()错误造成的。检查您的代码。

我在使用readdir()时遇到了与空白文件名相同的问题。结果证明,目录名是错误的,linux是区分大小写的,在代码中,目录名以“I”开头,在linux中,目录以“I”开头


我猜这个错误是由于没有处理opendir()错误造成的。检查您的代码。

我在使用readdir()时遇到了与空白文件名相同的问题。结果证明,目录名是错误的,linux是区分大小写的,在代码中,目录名以“I”开头,在linux中,目录以“I”开头


我猜这个错误是由于没有处理opendir()错误造成的。检查您的代码。

我在使用readdir()时遇到了与空白文件名相同的问题。结果证明,目录名是错误的,linux是区分大小写的,在代码中,目录名以“I”开头,在linux中,目录以“I”开头

我猜这个错误是由于没有处理opendir()错误造成的。检查你的代码