This article mainly introduces how to create and delete php folders. The example analyzes the tips for creating and deleting php folders. For more information, see
This article mainly introduces how to create and delete php folders. The example analyzes the tips for creating and deleting php folders. For more information, see
This article describes how to create and delete php folders. 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, which 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.