Focus on the application of file functions in PHP
PHP has many file system-related functions that not only open files, but also display content, move files, and other features in the directory, and many people even use PHP to develop internet-based file Explorer.
The following script sample can display a list of directories that are already included in the code:
? / the full path name of the directory to be read into a variable named $dir_name. /
$dir _name = "/home/me/";
/ creates a handle whose value is the result of opening a given directory /
$dir = Opendir ($dir _name);
/ creates a block of text to place the list element (file name) /
$file _list = "
";
/ uses a while statement to read all the elements in a directory that is already open, if the file name is not "." or "..", the name in the list is displayed/
while ($file _name = Readdir ($dir)) {
if ($file _name!= ".") &&&& ($file _name!= "...")) {
$file _list. = "
- $file _name";
}
}
$file _list. = "
";
/ closes the Open Directory and ends the PHP module /
Closedir ($dir);
? >
!--Start your HTML-->
Directory Listing
!--use PHP to print the name of this directory you read-->
Files in:? echo "$dir _name";? >
!--use PHP to print the directory listing-->
? echo "$file _list";