Home > Article > Backend Development > first day of my life php is_file and is_dir usage precautions when traversing directories
1. The directory inc has the following contents:
Subdirectory 0
Subdirectory a
footer.html
header.html
login_function.inc.php
mysqli_connect.php
style.css
2. Now PHP needs to traverse the inc directory and only Display files, do not display directories 0 and a, the code is as follows:
Copy code The code is as follows:
$dir = $_SERVER['DOCUMENT_ROOT'];
$dir = "$dir/inc/";
$d = opendir($dir);
while(false !==($f=readdir($d)))
{
if(is_file($f)){
echo "
Copy the code The code is as follows:
while(false !== ($f=readdir($d)))
{
if(is_file ("$dir/$f")){
echo "
The above introduces the usage notes of first day of my life php is_file and is_dir when traversing directories, including the content of first day of my life. I hope it will be helpful to friends who are interested in PHP tutorials.