This article describes php file operations in detail (1). If you need it, you can refer to the following section to determine the file type.
Var_dump (filetype (". /img "); // return the file type, directory or file var_dump (is_dir (". /img/11.png"); // checks whether the given file is a directory is_file (); // checks whether the given file is a file.
File attributes
Var_dump (date ("Y-m-d H: I: s", fileatime (". /img/11.png"); // last file access time var_dump (date ("Y-m-d H: I: s", filemtime (". /img/11.png"); // file modification time echo filesize (". /img/11.png"); // file size filectime ("") // file creation time file_exists ("") // File existence
File path
/Indicates that the root page represents the www Directory. php indicates the disk root var_dump (file_exists ("/wamp/www/1220/wenjian/img/11.png ")); // whether the file contains echo $ _ SERVER ['document _ root']; // Obtain the server root path echo basename ("/wamp/www/1220/wenjian/img/11.png "); // Obtain the file name echo dirname ("/wamp/www/1220/wenjian/img/11.png") in the path "); // directory name var_dump (pathinfo ("/wamp/www/1220/wenjian/img/11.png") in the path; // returns the array echo realpath (". /img/11.png"); // converts relative paths to absolute paths.
Traverse directories
Var_dump (glob ("./ajax/*"); // returns an array of all files in the directory.
Give me a folder and return the number of all files in the folder
function ShuLiang($url){ $sl = 0; $arr = glob($url); foreach($arr as $v) { if(is_file($v)) { $sl++; } else { $sl += ShuLiang($v."/*"); } } return $sl;}echo ShuLiang("./ajax/*");
The above is a detailed description of PHP file operations (1). For more information, see other related articles in the first PHP community!