Linux Server maintenance with PHP implementation maintenance file code

Source: Internet
Author: User
PHP has a lot of file system related functions, not only to help you open the file, you can also display directory content, move files and so on. Many people even use PHP to write out a Web-based file manager.
The first thing you need to do is remind yourself of something about the file path: In Windows you can use the slash "/" or the backslash "\" in the file path, while the other operating systems use only "/". For compatibility reasons, the following instances use the "/" representation:
The following simple script shows a basic list of directories. The comment is in the code and explains each step:
$dir _name = "/home/me/";
/* Create a handle to open the result of a given directory */
$dir = Opendir ($dir _name);
/* Start a text to add to the place where the list element (filename) will be placed */
$file _list = "
      ";
      /* Use the while statement to read all the elements of the Open directory. If the file name is not "." and ".." The file name is output in the list */
      while ($file _name = Readdir ($dir)) {
      if ($file _name! = ".") && ($file _name! = ")") {
      $file _list. = "
    • $file _name ";
      }
      }
      /* End list */
      $file _list. = "
";
/* Close the Open Directory handle and end the PHP code snippet */
Closedir ($dir);
?>



<title>Directory Listing</title>



Files in:






Congratulations, there is already a list of directories. Remember that to read the directory or file (as you will see in a moment) the PHP running platform must have at least Read permission to the directory or file.
Here's an example of how to copy a file:
$original = "/home/me/mydatabasedump";
$copied = "/archive/mydatabasedumo_1010";
/* Copy the source file to the destination using the function copy () or end with an output error message */
@copy ($original, $copied) or Die ("couldn ' t copy file.");
?>
The sample script is the first step in the backup system. When the script runs, it first copies the database to a different location for security reasons. By modifying the crontab, you can execute the file at the selected time without user intervention.
Assuming Lynx is already on the system, you can create a crontab portal to run Lynx and access the files. Accessing the file runs the script and creates the copied file. The following example runs the script at 5 o'clock in the morning and then turns off Lynx:
0 5 * * * [username] lynx-dump http://localhost/copyfile.php 1>/dev/null 2>&1
If you are running a CGI version of PHP, you can skip the Lynx section and refer to the binary file:
0 5 * * * [username] php/path/to/copyfile.php 1>/dev/null 2>&1

The above describes the Linux server maintenance with PHP implementation to maintain the file code, including the Linux server maintenance content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.