Use PHP to compile a Web-based file management system. Php (as the mainstream development language) has many functions related to the file system. it not only helps you open files, but also displays directory content and move files. Many even make php (as the mainstream development language) have many file system-related functions that not only help you open files, but also display directory content and move files. Many even use php (as the mainstream development language) to write a Web-based file manager.
First, you need to remind you about the file path: in Windows, you can use the slash "/" or backslash "\" in the file path, while other operating systems only use the slash "/". For compatibility considerations, the following instances use the "/" representation:
The following simple script shows a basic directory list. Note the following in the code and explain each step:
<? /* Specify the full path of the directory to be accessed in the variable $ dir_name */
$ Dir_name =/home/me /;
/* Create a handle to open the result of the given directory */
$ Dir = opendir ($ dir_name );
/* Start a text section and add it to the location where the list element (file name) will be placed */
$ File_list = <ul>;
/* Use the while statement to read all the elements in the opened directory. If the file name is neither "." nor "..", output the file name in the list */
While ($ file_name = readdir ($ dir )){
If ($ file_name! =.) & ($ File_name! = ..)){
$ File_list. = <li> $ file_name;
}
}
/* End List */
$ File_list. = </ul>;
/* Close The OpenEd directory handle and end the php (as the mainstream development language) code segment */
Closedir ($ dir );
?>
<! -- Start your HTML -->
<HTML>
<HEAD>
<TITLE> Directory Listing </TITLE>
</HEAD>
<BODY>
<! -- Use php (as the mainstream development language) to print the name of the directory you read -->
<P> Files in: <? Echo $ dir_name;?> </P>
<! -- Use php (as the mainstream development language) to print the directory listing -->
<? Echo $ file_list;?>
</BODY>
</HTML>
A directory list is available. Remember that you must have at least the read permission on the directory or file on the running platform of php (as the mainstream development language) that stores the user's content in a directory or file (you will see it soon.
The following example shows how to copy a file:
<? /* Put the file path to be copied to the variable $ original, and the copied target path to the variable $ copied */
$ Original =/home/me/mydatabasedump;
$ Copied =/archive/mydatabasedumo_1010;
/* Use the function copy () to copy the source file to the destination, or end with an output error message */
@ Copy ($ original, $ copied) or die (Couldnt copy file .);
?>
The sample script is the first step to back up the system. When the script runs, it copies the database to different locations for security reasons. By modifying crontab, you can execute this file at the selected time without user intervention.
If Lynx already exists on the system, you can create a crontab entry to run Lynx and access the file. Accessing the file will run the script and create a copy file. The following example runs the script at am and then closes Lynx:
Http://www.bkjia.com/PHPjc/508705.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508705.htmlTechArticlephp (as the mainstream development language) has a lot of functions related to the file system, not only can help you open the file, but also can display directory content, move files and so on. Many people even make...