PHP Operation directory
Create a new directory mkdir() u description: Try to create a new directory specified by pathName. Bool mkdir (string pathName [, intPathName [,int pathName [, intMode = 0777 [, bool recursive=false]]) Nrecursive =false]])u parameter: nrecursive =false]])u parameter: npathName: specifies the directory path; N mode: The default mode is 0777, which means the maximum possible access. Mode: The default mode is 0777, which means the maximum possible access. Mode: The default mode is 0777, which means the maximum possible access. Mode is ignored on Windows. Note that the mode value is octal. The value of nmode is octal. The n mode value is octal. Nrecursive: If the parent directory of the specified path does not exist, it will also be created recursively. U Return value: TRUE on success, FALSE on failure.
<? $dirname = "./ a/b/c/d"; Mkdir ($dirname,0777,true) is created recursively if the upper directory does not exist;Copy the code
Check whether the current file is a file or directory is_dir()
U Description: Checks whether the given file name is a directory. U syntax: bool is_dir (string $filename) u returned value: TRUE if the filename exists and it is a directory, FALSE otherwise.
<? $dirname = "./public"; If (is_dir($dirname)) {echo "{$dirname} is a directory!" ; }else {echo "{$dirname} is a file!" ; }Copy the code
Check whether a file exists file_exists()
U Syntax: bool file_exists (string $filename) U Indicates whether a file or directory exists. Return: TRUE if the file or directory specified by filename exists, FALSE otherwise.
<? $dirname = "./public"; If (file_exists($dirName)) {echo "{$dirname} file exists! <br>"; If (is_dir($dirname)) {echo "{$dirname} is a directory!" ; }else {echo "{$dirname} is not a directory! ; }}else {echo "{$dirname} file does not exist!" ; }Copy the code
Delete directory rmdir()
ø Syntax: bool RMDIR (string dirName) ø parameter: dirname) ø Parameter: dirname) ø Parameter: dirname Directory path. ø Return value: Returns TRUE on success, or FALSE on failure. ø Hint: Try to delete the directory specified by dirname. The directory must be empty and have corresponding permissions.
<? $dirname = "./public"; If (file_exists($dirname)) {if(is_dir($dirname)) {// Delete directory: the directory must be empty rmdir($dirname); }}Copy the code
Change directory access permissions chmod()
U Description: Changing the file access permission U Syntax: bool chmod (string filename,intfilename,intfilename,intmode) u Parameter: n filename, indicates the file path. Nfilename specifies the path to the file. N filename: specifies the file path. The nmode, mode parameter contains three octal numbers that specify the owner, the owner’s group, and the owner’s access limits in order. Each section can calculate the desired permissions by adding the required permissions. The number 1 means making the file executable, the number 2 means making the file writable, and the number 4 means making the file readable. Add these numbers to specify the permissions you need. N Warning: The file in Windows has the read-only permission of 0444. Folder read-only permission 0555. U Note: this function does not work on remote files.
$dirname = "./05 "; Chmod ($dirname,0754); $dirname ($dirname,0754);Copy the code
Fileperms ();
ø Syntax: int fileperms (string $filename) Return value: returns the access permission of the file in decimal digits.
<? $dirname = "./05 "; $dirname = ". Chmod ($dirname,0754); $dirname ($dirname,0754); $int = fileperms($dirname); $int = decoct($int); Echo substr($int,2);Copy the code