Use PHP to protect the file system

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

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.