This article mainly introduces how to create and delete php folders, and analyzes how to create and delete folders in php, for more information about how to create and delete php folders, see the following example. Share it with you for your reference. The details are as follows:
1. create a folder
The code is as follows:
<? Php
// Create a folder
$ File_path = "d:/fold /";
If (! File_exists ($ file_path )){
Mkdir ($ file_path );
Echo "folder created ";
} Else {
Echo "the folder already exists ";
}
?>
2. create folders and recursively create
The code is as follows:
<? Php
// Create a folder with multiple layers of nested folders (recursive)
$ File_path = "d:/fold/aaa/bbb /";
If (! File_exists ($ file_path )){
Mkdir ($ file_path, 0777, true); // 0777 indicates the folder permission. the folder permission is invalid by default in windows. However, you must enter this parameter because the third parameter is used; true/false indicates whether folders can be recursively created
Echo "folder created ";
} Else {
Echo "the folder already exists ";
}
?>
3. delete folders
The code is as follows:
<? Php
// Delete a folder
$ File_path = "d:/fold/aaa/bbb /";
If (is_dir ($ file_path) {// first judge whether it is a folder.
If (rmdir ($ file_path) {// determines whether the deletion is successful.
Echo "folder deleted ";
} Else {
Echo "folder cannot be deleted"; // if the folder is not empty, it cannot be deleted.
}
} Else {
Echo "the folder does not exist ";
}
?>
I hope this article will help you with php programming.