Phpdir function tutorial. Listing files sometimes makes it a pleasure to use PHP to list all files in a directory. To do this, use the directory class. First, we must start to look at the Directory of the directory object. Public documents
Sometimes, it is a pleasure to use PHP to list all files in a directory. To do this, use the directory class.
First, we must start to look at the Directory of the directory object. Use 'in the current directory '. ', Because this references the current directory.
$ Dir = dir ('.');
?>
The next part is a bit complex, but this is because of the PHP file recommendations, complicated, but short-term approach to do it.
I am using the simultaneous control structure through all entries in the loop. Under the conditions, I tested whether it is a directory-> "PLEASE READ () and return false (right! = Carrier testing is of the correct type, so it is not '''rated as 0 or false because it will be non-type sensitive carrier ). I also confirm the expression in the $ File, but the transfer will return the final value of the file after the transfer. Dollar Directory-> "please read () method will return false when there are no more files, it will break the loop.
While (false! ==( $ File = $ dir-> read ())){
Echo $ file. "n ";
}
?>
If you are using an html file, you will use
It is not a line break, and such a file will appear on the new production line on your webpage.
If you run the code before, you will find that the output of your script is listed in two strange files :. And... are all referring to the current directory (the '.'), and parent directory (in '..').
If you want to exclude these from your list, just write a declaration and ignore it if it checks whether the variable for the file is of these values if there is.
While (false! ==( $ File = $ dir-> read ())){
If ($ file! = '.' & $ File! = '..'){
Echo $ file. "n ";
}
}
?>
Therefore, it is necessary to close the instance directory level when you are working with them to clean the resources, and announce the operating system, you are done with it.
$ Dir-> close ();
?>
This is the end of learning how to use PHP to list files. On the next page, you will learn how to upload files from a directory server. After I sent the next page to you, however, I actually used a directory in the archive list to retrieve external data from the Kirupa tutorial.
Yay, this is the last page! In the past, you learned more practical file processing skills, and we will summarize them on this page.
Sometimes, it is a pleasure to use PHP to list all files in a directory. To do this, use the directory class. First, we must start to look at the Directory of the directory object ....