Use PHP to compile a Web-based file management system

Source: Internet
Author: User
You can use PHP to compile a Web-based file management system. For more information, see using PHP to compile a Web-based file management system. PHP has many file system-related functions that not only help you open files, you can also display directory content and move files. Many even use PHP to write a Web-based file manager. First you need to remind something about the file path: in the "> <LINKhref =" http://www.ph

PHP has many file system-related functions that not only help you open files, but also display directory content and move files. Many even use PHP 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. other operating systems only use "/". 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 code segment */

Closedir ($ dir );

?>

<! -- Start your HTML -->

<HTML>
<HEAD>
<TITLE> Directory Listing </TITLE>
</HEAD>

<BODY>
<! -- Use PHP to print the name of the directory you read -->
<P> Files in: <? Echo $ dir_name;?> </P>
<! -- Use PHP to print the directory listing -->
<? Echo $ file_list;?>
</BODY>
</HTML>

A directory list is available. Remember that to read 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:

<? /* 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 (Couldn'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 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:

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:

0 5 *** [username] php/path/to/copyfile. php 1>/dev/null 2> & 1

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.