1. Catalogue Inc has the following contents:
Sub-Catalog 0
Sub-Directory A
Footer.html
Header.html
login_function.inc.php
mysqli_connect.php
Style.css
2, now PHP to traverse the INC directory, and only display files, do not display directories 0 and a, the code is as follows:
Copy the Code code as follows:
$dir = $_server[' document_root ');
$dir = "$dir/inc/";
$d = Opendir ($dir);
while (False!== ($f =readdir ($d)))
{
if (Is_file ($f)) {
echo "
$f
";
}else{
echo "
is the directory $f
";
}
}
Closedir ($d);
The results only show that "footer.html" is a file, and the others become directories:
is the directory.
is the directory:
is directory A
Footer.html
is the directory header.html
is the directory login_function.inc.php
is the directory mysqli_connect.php
is the directory Style.css
This is because the "$f" can not be used directly in Is_file and Is_dir, this will be treated as PHP as the root directory of the file, and in my root directory has footer.html this file, so the file will be displayed correctly. Others are not. Change the code to:
To display correctly, the code needs to be modified:
Copy the Code code as follows:
while (False!== ($f =readdir ($d)))
{
if (Is_file ("$dir/$f")) {
echo "
$f
";
}else{
echo "
is the directory $f
";
}
}
Closedir ($d);
The above describes the usage considerations for the first day of my life php is_file and Is_dir used to traverse the directory, including the first day's my life content, and I want to be helpful to friends who are interested in PHP tutorials.