File System processing and File Processing
(Filetype (". /test "); // determines whether it is a file or a directory * (is_file (". /aa.txt "); // determines whether the file is * is_dir (". /test "); // determines whether the echo fileatime (". /aa.txt "); // returns the timestamp echo date (" Y-m-d H: I: s ", fileatime (". /aa.txt "); // format the last access time of the file filectime (". /aa.txt "); // file creation time create echo date (" Y-m-d H: I: s ", filemtime (". /aa.txt "); // file modification time modification modify echo filesize (". /aa.txt "); // get the file size var_dump (file_exists (". /aaa.txt "); // determines whether the exist exists var_dump (file_exists ("/wamp/www/aa.jpg ");/indicates the root, which indicates the www directory in the webpage, in PHP, the disk ROOT echo $ _ SERVER ['document _ root'] is displayed. // the ROOT directory of the SERVER displays D:/phpStudy/WWW directory echo basename (". /aa.txt "); // obtain the file name basename in the path. The result of the youdao dictionary returns the file name (computer terminology) echo dirname (" DBDA. class. php "); // get the folder directory display in the path. var_dump (pathinfo ("DBDA. class. php "); // obtain the path information display array (4) {[" dirname "] => string (1 )". "[" basename "] => string (14)" DBDA. class. php "[" extension "] => string (3)" php "[" filename "] => string (10)" DBDA. class "} echo realpath (". /12/aa.txt "); // convert the relative path to an absolute path to display the directory operation mkdir (". /aa "); // create the directory make => mkrmdir (". /aa "); // Delete the directory. The directory must be empty. remove => rmrename (". /test ",".. /ceshi "); // move the directory remove to traverse the directory var_dump (glob (". /qiyezhan /*. txt "); // obtain all files in the directory. The global declaration is a global variable $ GLOBALS. reference the global variables available in the global scope to open the Directory and return the directory resource $ dname = ". /0504 "; $ dir = opendir ($ dname); read the file from the directory resource. Each time you read a while ($ fname = readdir ($ dir) {echo $ dname. "/". $ fname. "<br>" ;}close the directory resource closedir ($ dir); // close the file output result when the access file ends. /0504 /.. /0504 /... /0504/chuli. php. /0504/denglu. php. /0504/fabu. php. /0504/guanliyuan. php. /0504/login. php. /0504/suoding. php. /0504/tongguo. php. /0504/zhuce. php. /0504/zufangzi. php
For example, create a function for a folder and return the number of files in the folder echo fileCount (". /qiyezhan "); function fileCount ($ fname) {// The number of all files in the folder $ sum = 0; // determine whether the Given folder is a folder if (is_dir ($ fname )) {// open the folder $ dir = opendir ($ fname); while ($ wenjian = readdir ($ dir) {if ($ wenjian! = "." & $ Wenjian! = ".. ") {// Complete file path $ furl = $ fname. "/". $ wenjian; if (is_file ($ furl) {$ sum ++;} else if (is_dir ($ furl) {// get the number of files in this folder, accumulate $ sum = $ sum + fileCount ($ furl) ;}}// close the folder closedir ($ dir); return $ sum ;} else {echo "Incorrect folder ";}}