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. /
= "/home/me/";
/ creates a handle whose value is the result of opening a given directory /
= Opendir ();
/ creates a block of text to place the list element (file name) /
= "
/ uses a while statement to read all the elements in a directory that is already open, if the file name is not "." or "..", the names in the list are displayed /
while (= Readdir ()) {
if ((!= ".") &&&& (!= "...")) {
. = "
";
}
}
. = "";
/ closes the Open Directory and ends the PHP module /
Closedir ();
? >
!--Start your HTML-->
Directory Listing
!--use PHP to print the name of this directory you read-->
Files in:
!--use PHP to print the directory listing-->
? echo "";
Well, we've got a list of directories. It is important to note that to read a file (which we will explain later) or the contents of the directory, the user on the system on which PHP is running must have at least the right to read the file.
Here is an example of how to copy a file:
? / assign the full path of the source file you want to copy to a variable named, and assign the full path of the copied file to a variable named /
= "/home/me/mydatabasedump";
= "/archive/mydatabasedumo_1010";
/ uses the copy () function to copy the source file and displays an error message if the copy is not completed /
@copy (,) or Die ("couldn ' t copy file.");
? >
This example is a prototype of a file backup system. When the script runs, it copies the files to a different location for saving. By modifying the daemon a little, you can execute it at the moment you specify in the day without the intervention of the user.