A. Question and answer question
1. What is the function that returns the part of the file name in the path?
2. What is the function of changing the file mode?
3. What is the function of copying files?
4. What is the function that returns the directory part of the path?
Two. Programming questions
1. Please write the function in three ways, get an associative array of all the file and folder names in a directory, request a path parameter to the function, return an array, in the format: Array (' dir ' =>array (' dir1 ', ' dir2 ' ...), ' file ' = Array ())
2. Encapsulate a System file class, the class methods include: Determine whether the file exists, get the contents of the file (including lock and lock file), input content to a file, append the content to the file, delete the file, move the file, copy the file, the file name part, the directory part of the file,
The suffix part of the file, the mine type of the file, the size of the file, the last modification time of the file, whether it is a path, determine whether the file is writable, determine whether it is a file, create a folder, copy a directory, delete a directory.
Answer
A. Question and answer question
1.string basename ( string $path
[, string $suffix
])
2.bool chmod ( string $filename
, int $mode
)
< Span class= "type" >3. bool copy ( string $source
, < Span class= "type" >string $dest
[, resource $context
])
4.string dirname ( string $path
)
Two. Programming questions
1
functionScanDir1 ($dir= './'){ $result[' dir '] =$result[' file '] =Array(); if(!Is_dir($dir))return $result; foreach(Scandir($dir) as $DF) { if($DF= = = '. ' | |$DF= = = '. ')Continue; if(Is_dir($dir.‘ /‘.$DF))$result[' dir '] [] =$DF; if(Is_file($dir.‘ /‘.$DF))$result[' File '] [] =$DF; } return $result;}functionScanDir2 ($dir= './'){ $result[' dir '] =$result[' file '] =Array(); if(!Is_dir($dir))return $result; $handle=dir($dir); while(($DF=$handleRead ())!==false) { if($DF= = = '. ' | |$DF= = = '. ')Continue; if(Is_dir($dir.‘ /‘.$DF))$result[' dir '] [] =$DF; if(Is_file($dir.‘ /‘.$DF))$result[' File '] [] =$DF; } $handle-Close (); return $result;}functionSCANDIR3 ($dir= './'){ $result[' dir '] =$result[' file '] =Array(); if(!Is_dir($dir))return $result; $handle=Opendir($dir); while(($DF=Readdir($handle)) !==false) { if($DF= = = '. ' | |$DF= = = '. ')Continue; if(Is_dir($dir.‘ /‘.$DF))$result[' dir '] [] =$DF; if(Is_file($dir.‘ /‘.$DF))$result[' File '] [] =$DF; } return $result;}
PHP File Related function questions