Focus on learning how to use file functions in PHP. There are many functions related to file systems in PHP. these functions can not only open files, but also display contents in directories, move files, and other functions, many people even use PHP for Internet-based development
Focus on learning how to use file functions in PHP
PHP has many functions related to the file system. these functions can not only open files, but also display contents in directories, move files, and other functions, many people even use PHP to develop an Internet-based file resource controller.
The following script example shows a directory list with annotations included in the code:
<? /? Store the full path name of the directory to be read into a variable named $ dir_name. /
$ Dir_name = '/home/me /';
/? Create a handle whose value is the result of opening a given directory? /
$ Dir = opendir ($ dir_name );
/? Create a text block to place the list element (file name )? /
$ File_list = '<ul> ';
/? Apply a while statement to read all the elements in the opened Directory. 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. = '<li> $ file_name ';
}
}
$ File_list. = '</ul> ';
/? Close the opened directory and end the PHP module? /
Closedir ($ dir );
?>
<! -- Start your HTML -->
<HTML>
<HEAD>
<TITLE> Directory Listing </TITLE>
</HEAD>
<BODY>
<! -- Use PHP to print the name of the directory you read -->
<P> Files in: <? Echo '$ dir_name';?> </P>
<! -- Use PHP to print the directory listing -->
<? Echo '$ file_list';?>