Php Folder creation and deletion Methods

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.