Home > Backend Development > PHP Tutorial > How to create and delete php folders, _PHP tutorial

How to create and delete php folders, _PHP tutorial

WBOY
Release: 2016-07-13 10:09:09
Original
857 people have browsed it

How to create and delete php folder,

The example in this article describes how to create and delete php folders. Share it with everyone for your reference. The details are as follows:

1. Create a folder

Copy code The code is as follows:
//Creation of folder
$file_path = "d:/fold/";
if(!file_exists($file_path)){
mkdir($file_path);
echo "Folder created successfully";
}else{
echo "The folder already exists";
}
?>

2. Create folders, recursively

Copy code The code is as follows:
//Create folders, multi-layer nested folders (recursive)
$file_path = "d:/fold/aaa/bbb/";
if(!file_exists($file_path)){
mkdir($file_path,0777,true);//0777 indicates folder permissions, which is invalid by default in Windows, but because the third parameter is used here, it must be filled in; true/false indicates whether the folder can be created recursively
echo "Folder created successfully";
}else{
echo "The folder already exists";
}
?>

3. Delete the folder

Copy code The code is as follows:
//Delete folder
$file_path = "d:/fold/aaa/bbb/";
if(is_dir($file_path)){//First determine whether it is a folder
if(rmdir($file_path)){//Determine whether the deletion can be successful
echo "Folder deleted successfully";
}else{
echo "Cannot delete folder";//If the folder is not empty, it cannot be deleted
}
}else{
echo "The folder does not exist";
}
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947216.htmlTechArticleHow to create and delete php folders. This article describes the creation and deletion methods of php folders. Share it with everyone for your reference. The details are as follows: 1. Create a folder and copy the code...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template