这篇文章主要介绍了php文件夹的创建与删除方法,实例分析了php创建与删除文件夹的技巧,需要的朋友可以参考下
本文实例讲述了php文件夹的创建与删除方法。分享给大家供大家参考。具体如下:
1、创建文件夹
复制代码 代码如下:
//文件夹的创建
$file_path = "d:/fold/";
if(!file_exists($file_path)){
mkdir($file_path);
echo "创建文件夹成功";
}else{
echo "文件夹已存在";
}
?>
2、创建文件夹,递归式创建
复制代码 代码如下:
//创建文件夹,多层嵌套的文件夹(递归式)
$file_path = "d:/fold/aaa/bbb/";
if(!file_exists($file_path)){
mkdir($file_path,0777,true);//0777表示文件夹权限,windows默认已无效,但这里因为用到第三个参数,,得填写;true/false表示是否可以递归创建文件夹
echo "创建文件夹成功";
}else{
echo "文件夹已存在";
}
?>
3、删除文件夹
复制代码 代码如下:
//删除文件夹
$file_path = "d:/fold/aaa/bbb/";
if(is_dir($file_path)){//先判断是不是文件夹
if(rmdir($file_path)){//判断是否能删除成功
echo "删除文件夹成功";
}else{
echo "无法删除文件夹";//如果文件夹不为空,是无法删除的
}
}else{
echo "文件夹不存在";
}
?>
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.