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

Will there be two more pictures every time?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-18 09:16:10
Original
1207 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:

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

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

Final form:

$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);
    }
}
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
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template