Document Concept:
The first one is the Windows file, the other PHP according to the Linux files, the two are different, we say that the page based on Windows file can be a folder (that is, directory) or files, and PHP must have both, it contains directories and files 2 kinds.
1. Determine the file type
(1) Get the file type filetype ("./images")
For example: Var_dump (FileType ("./img")); Returns the file type, directory, or file, and if it is a directory, returns dir, or file if it is.
(2) Determine if the directory type is Is_dir ("")
Determine if the file type is Is_file ("")
For example: Var_dump (Is_dir ("./img/11.png"));
Var_dump (Is_file ("./img/11.png"));
2. File attributes
(1) file last access time Fileatime ("") whose return value is timestamp
File creation time Filectime ("")
File modification Time Filemtime ("")
File size FileSize ("")
Whether the file already exists file_exists ("") This is more commonly used
For example: Var_dump (Date ("Y-m-d h:i:s", Fileatime ("./img/11.png"))); Returns the normal time for the last access
3. File path
(1) Current path./For example:./date
(2) Parent path: /For example:.. /img
(3) Mode of root Path page: root directory for www example:/1220/wenjian/img/11.png
PHP Mode: Root directory is disk, that is, operating system root for example:/wamp/www/1220/wenjian/img/11.png
(4) Take the root directory of the server $_server[' Document_root ' For example: Echo $_server[' Document_root '];
(5) Get the filename basename ("path") in the path, for example: Echo basename ("/wamp/www/1220/wenjian/img/11.png"); return 11.png
basename ("Path", ". Php/.txt") For example: Echo basename ("/wamp/www/1220/wenjian/img/11.png", ". png"), return 11
(6) Directory name dirname ("path") in the path, for example: Echo dirname ("/wamp/www/1220/wenjian/img/11.png");
(7) returns the array pathinfo ("path")
(8) Returns the normalized absolute path Realpath ("path") For example: Echo Realpath ("./img/11.png");//The value of converting a relative path to an absolute path is/WAMP/WWW/1220/WENJIAN/IMG/11. Png
4. Directory Operations
(1) traversing the array glob ("./fenye/*.php")
Example: give you a folder that returns the number of files in that folder
<?php
Recursive function Implementation function
function Fileall ($fname) {
$sum = 0;
if (Is_dir ($fname)) {
$dir = Opendir ($fname);
while ($name = Readdir ($dir)) {
if ($name! = "." &&$name! = "..."){
$wzpath = $fname. " /". $name;//stitching files into a full path
if (Is_file ($wzpath) {//If it is a file +1
$sum + +;
}else{//if the folder calls itself function to find all files
$sum + =Fileall ($wzpath);
}
}
}
Closedir ($dir);
return $sum;
}else{
return 1;
}
}
Function call: EchoFileall ("./bootstrap");
?>
PHP File System Management