This article summarizes some functions and usage methods of PHP directory operations, including: creating directories, traversing directories, reading directories, closing directories, opening directories, etc. About PHP directory operation functions, friends in need can refer to them.
php creates directory folder function mkdir(), its structure is as follows:
kdir(string $dirname,[int $mode])
The parameter $dirname is the name of the directory you want to create, and the parameter $mode is optional and is an integer variable indicating the creation mode.
closedir($dp);
}
directory("e:wp");
?>
The PHP directory reading function readdir() can read all files and folders in the directory. Its structure is as follows:
readdir($dp);
The parameter $dp is the resource object returned by using the function opendir() to open the directory. The function returns the file name in the directory.
Example:
The code is as follows
Copy code
");
}
?>
php closes the directory function using closedir(), its structure is as follows:
closedir($dp)
The parameter $dp is the resource object returned by using the function opendir() to open the directory.
Example:
Using the function closedir() to successfully close a directory does not return the value 1, so you cannot use the if statement to determine whether the directory is closed successfully
I have introduced a series of file operations in PHP before, and then the author will introduce how to operate the directory. The function of the PHP directory function is similar to that of the file function. Here we first introduce the open directory function opendir(). Its structure is as follows:
opendir(string $path)
The parameter $path is the path to the directory to be opened, and the function will return a handle to the opened directory, which is used to store the current directory resources. Before opening a directory, you must first determine whether the directory exists, using the is_dir() function.
Example:
The code is as follows
代码如下
复制代码
if (is_dir("stufdy")){
opendir("studfy");
print_r("目录成功打开");
}
else
echo "目录不存在";
?>
The PHP pointer function rewind() can set the file location pointer to the beginning of the file. Its structure is as follows:
bool rewind (resource $handle );
The function returns a Boolean value, true if successful and false if failed. Example:
The code is as follows
Copy code
"; /*Output the first line*/
echo fgets($f)." "; /*Output the second line*/
rewind($f); /*The pointer returns the file header*/
echo fgets($f); /*Output the first line*/
?>
http://www.bkjia.com/PHPjc/628848.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628848.htmlTechArticleThis article summarizes some functions and usage methods of PHP directory operations, including: creating directories, traversing directories, reading Fetch directory, close directory, open directory, etc. About php directory operations...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn