Examples of dynamic web skills PHP file system development

Source: Internet
Author: User
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';?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.