PHP File System Management (instance description ),

Source: Internet
Author: User

PHP File System Management (instance description ),

File concept:

The first is a windows file, and the other php is different from the LINUX file. The page based on windows can be folders (directories) or files, php must both have two types of files and directories.

1. Determine the file type

(1) obtain the file type filetype ("./images ")

For example: var_dump (filetype ("./img"); // return the file type, directory, or file. If it is a directory, return dir. If it is a file, return file;

(2) Determine whether the directory type is is_dir ("")

Determine whether the file type is is_file ("")

Example: var_dump (is_dir ("./img/11.png "));

Var_dump (is_file ("./img/11.png "));

2. File Attributes

(1) The last time the file was accessed, fileatime ("") returns a timestamp.

File Creation Time: filectime ("")

File modification time filemtime ("")

File Size filesize ("")

Whether the file already exists file_exists ("").

For example: var_dump (date ("Y-m-d H: I: s", fileatime ("./img/11.png"); returns the normal time of the last access

3. File Path

(1) Current path./For example:./date

(2) superior path ../example: ../img

(3) root path 

Page mode: the root directory is www
Example:/1220/wenjian/img/11.png
Php mode: the root directory is a disk, that is, the operating system root.
Example:/wamp/www/1220/wenjian/img/11.png

(4) retrieve the root directory of the server 

$ _ SERVER ['document _ root']
Example: echo $ _ SERVER ['document _ root'];

(5) Get the file name in the path  

Basename ("path ")
Example: echo basename ("/wamp/www/1220/wenjian/img/11.png ");
Returns 11.png.
Basename ("path", ". php/. txt ")
Example: echo basename ("/wamp/www/1220/wenjian/img/11.png",". png ");
11 is returned.

(6) directory name in the path

Dirname ("path ")
Example: echo dirname ("/wamp/www/1220/wenjian/img/11.png ");
Img is returned.

(7) returned array

Pathinfo ("path ")

(8) return the normalized absolute path.

Realpath ("path ")
Example: echo realpath ("./img/11.png"); // convert relative paths to absolute paths
The obtained value is/wamp/www/1220/wenjian/img/11.png.

4. Directory operations

(1) traverse the array glob ("./fenye/*. php ")

Instance: returns the number of all files in a folder.

<? Php // recursive function implementation function fileall ($ fname) {$ sum = 0; if (is_dir ($ fname) {$ dir = opendir ($ fname ); while ($ name = readdir ($ dir) {if ($ name! = "." & $ Name! = ".. ") {$ Wzpath = $ fname. "/". $ name; // concatenate the file into the complete path if (is_file ($ wzpath) {// if it is a file + 1 $ sum ++ ;} else {// call the function of the folder itself to find all files $ sum + = fileall ($ wzpath) ;}} closedir ($ dir); return $ sum ;} else {return 1 ;}} function call: echo fileall (". /bootstrap ");?>

The above PHP File System Management (instance description) is all the content shared by the editor. I hope you can give us a reference and support the help house.

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.