Home > Article > Backend Development > Will there be two more pictures every time?
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?
<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>
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?
<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.