Will there be two more pictures every time?

WBOY
Release: 2016-08-18 09:16:10
Original
1155 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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>
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template