繁体   English   中英

使用opendir / readdir函数后重复文本

[英]repeating text after using opendir/readdir functions

为什么发生这种情况对我来说还是个谜。 所以这是代码:

$dir = 'test/';
$de = opendir($dir);
if ($de) {
    while (($file = readdir($de)) !== false) {
        $path = $dir . $file;
        $file_title = 'this text gets repeated three times, each followed by a dot' . $file;
        echo $file;
    }
} else {
    echo "invalid directory";
}

因此,如果$ file = video.mp4和$ file_title ='文件名'。$ file; 它看起来像这样:

'file name.file name.file namevideo.mp4',如果变量前没有字符串,即$ file_title = $ title,则变量前会有三个点,如下所示:... video.mp4

如果有人知道发生了什么,请告诉我。 谢谢。

您会重复文本,因为您的代码包含一个循环。 那就是while做什么:它反复运行代码。

您正在列出. ..目录,请使用is_file()进行检查,以使该条目实际上是文件而不是目录:

if (is_file($dir . $file)) {
   // entry is a file
}

在这里,您可以阅读有关dot目录的更多信息: dot 有很多内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM