Home  >  Article  >  Backend Development  >  Will there be two more pictures every time?

Will there be two more pictures every time?

WBOY
WBOYOriginal
2016-08-18 09:16:101098browse

There is only one picture in the folder. Every time there are two more pictures. The pictures cannot be displayed. But when I look at the two pictures, the src is empty. It is the src of the picture below. Why is this?
Will there be two more pictures every time?
Will there be two more pictures every time?

<code>$dir = "upload2/"; 
    if (is_dir($dir)){
        if ($dh = opendir($dir)){
        while (($file = readdir($dh))!= false){
            $filePath = $dir.$file;
            echo "<img src='".$filePath."'/>";
        }
        closedir($dh);
        }
    }</code>

Reply content:

There is only one picture in the folder. Every time there are two more pictures. The pictures cannot be displayed. But when I look at the two pictures, the src is empty. It is the src of the picture below. Why is this?
Will there be two more pictures every time?
Will there be two more pictures every time?

<code>$dir = "upload2/"; 
    if (is_dir($dir)){
        if ($dh = opendir($dir)){
        while (($file = readdir($dh))!= false){
            $filePath = $dir.$file;
            echo "<img src='".$filePath."'/>";
        }
        closedir($dh);
        }
    }</code>

The following code is taken from the official reference as a solution:

<code class="php"><?php
if ($handle = opendir('.')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            echo "$entry\n";
        }
    }
    closedir($handle);
}
?></code>

http://php.net/manual/en/func...

Final form:

<code class="php">$dir = "upload2/"; 
if (is_dir($dir)){
    if ($dh = opendir($dir)){
    while (($file = readdir($dh))!= false){
        if ($file != "." && $file != "..") {
            $filePath = $dir.$file;
            echo "<img src='".$filePath."'/>";
        }
    }
    closedir($dh);
    }
}</code>

. Represents the current directory
. . Represents the upper-level directory
You can determine whether it is a directory before outputting.

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