PHP has many functions related to the file system. they not only help you open files, but also display directory content and move files. Many people even use PHP to write a Web-based file controller. First, you need to prompt something about the file path.
PHP has many functions related to the file system. they not only help you open files, but also display directory content and move files. Many people even use PHP to write a Web-based file controller.
First, you need to prompt something about the file path: in Windows, you can apply the slash "/" or backslash "\" in the file path, while other control systems only apply "/". For compatibility considerations, the following example shows how to apply:
The following simple script shows a basic directory list. Note in the code and describe each step:
= '/Home/me /';
/* Create a handle to open the results of a given directory */
= Opendir ();
/* Start a text section and add it to the location where the list element (file name) will be placed */
='
';
/* Apply the while statement to read all elements in the opened directory. If the file name is neither "." nor "..", output the file name in the list */
While (= readdir ()){
If ((! = '.')&&(! = '..')){
. ='
- ';
}
}
/* End List */
. ='
';
/* Close The OpenEd directory handle and end the PHP code segment */
Closedir ();
?>
Directory Listing
Files in:
Congratulations, there is a directory list. Remember that to read the contents in a directory or file (you will see it soon), the user's PHP runtime platform must have at least the read permission on the directory or file.
The following example shows how to copy a file:
= '/Home/me/mydatabasedump ';
= '/Archive/mydatabasedumo_1010 ';
/* Copy () The application function to copy the source file to the target location, or end with an output error message */
@ Copy (,) or die ('cooldn' t 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 correcting crontab, you can perform this file at the selected time without the user's involvement.
If Lynx already exists on the system, you can create crontab imports to run Lynx and visit files. The visiting file will run the script and create a copy file. The following example runs the script at am and then closes Lynx:
0 5 *** [username] lynx-dump http: // localhost/copyfile. php 1>/dev/null 2> & 1
If you are running the CGI version of PHP, you can skip the Lynx section and refer to the binary file: