Maintaining file systems with PHP

Source: Internet
Author: User
Tags file system
PHP has a lot of file system-related functions, not only can help you open the file, you can also display the contents of the directory, mobile files and so on. Many people even use PHP to write a web-based file manager.





First you need to remind you of something about the file path: In Windows you can use a slash "/" or a backslash "\" in the file path, while the other operating system uses only "/". For compatibility reasons, the following example uses the representation of "/":

The following simple script shows a basic list of directories. Comments are in the code and explain each step:

? * * Give the full path of the directory you want to access in the variable $dir _name * *

$dir _name = "/home/me/";

/* Create a handle to open the result of a given directory

$dir = Opendir ($dir _name);

/* Start a piece of text to add to the place where the list element (file name) will be placed * *

$file _list = "<ul>";

/* Use the while statement to read all the elements of the Open directory. If the file name is not "." and ".." The file name is printed in the list.

while ($file _name = Readdir ($dir)) {

if ($file _name!= ".") && ($file _name!= "...")) {

$file _list. = "<li> $file _name";

}

}

/* END LIST * *

$file _list. = "</ul>";





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.