Files: Files + Directories
Determine the file type:
filetype ("path"); // returns a string Is_dir ("path"); // If the directory returns true to determine whether the file is directory is_file("path"); // contrary to Dir to determine whether the file is not a file
File properties:
Fileatime ("path"); // get file last access time Filectime ("path"); // Get file creation time Filemtime ("path"); // Get the file modification time filesize ("path"); // Get File Size file_exists ("path"); // To see if a file exists
/: (Root)
Root in Web page: representative www directory
Root in PHP: represents the disk directory
$_server [' Document_root ']; // gets the root www of the current server basename ("path"); // gets the file name in the path basename ("Path", "File type"); // gets the file name with the suffix removed dirname ("path"); // gets the part of the path that removes the file name PathInfo ("path"); // can get the file information returned is an array Realpath ("path"); // Convert A relative path to an absolute path (starting at the top-level directory)
Traverse Directory
Var_dump (glob// returns all files in the directory $attrglob("./touxiang/*"); foreach ($attras$v) { echo$v. <br> ";}
Get the number of all files (including folders) under a folder
This method is used to get the number of files under the specified folder
$fname= "./0904";$dir=Opendir($fname);//open a directory to return to the directory resource while($url=Readdir($dir)){ Echo $fname." /".$url." <br> ";}Closedir($dir);//Close Directory Resourceget the size of all files in a directoryfunctionFsize ($fname){ $size= 0; $dir=Opendir($fname); //traverse directories, find files, accumulate size while($u=Readdir($dir)) { if($u=="." ||$u=="..") { } Else { $zfname=$fname." /".$u; if(Is_file($zfname)) { $size+=filesize($zfname); } } } //find subdirectories, get the file size under subdirectories Rewinddir($dir); while($u=Readdir($dir)) { if($u=="." ||$u=="..") { } Else { $zfname=$fname." /".$u; if(Is_dir($zfname)) { $size+ = Fsize ($zfname); } } } Closedir($dir); return $size;}EchoFsize ("./0904");
PHP folder operations