search
Homephp教程php手册php 创建目录与php删除目录代码

php 创建目录与php删除目录代码

Jun 13, 2016 am 11:17 AM
dosmkdirphpandcodeclosecreatedeletemethodhaveTable of contentsSimple

创建目录就用mkdir有一点像dos里面的创建目录哦,方法很简单,关于删除目录,这里用了rmdir,但是只删除空目录,不能删除里面有文件或文件夹的目录,如果要删除不是空目录就要用递归来删除了/  

php教程 创建目录与php删除目录代码
/*
这是篇教程文章,要来告诉你如何利用php  创建目录 删除目录的方法,下面我们就来看看创建目录的实例吧。不过创建目录要有web权限才行啊。
*/

$dir_name = "www.bkjia.com";

if(mkdir($dir_name))    //在当前目录下创建目录tmp_data
{
    echo "目录".$dir_name."创建成功!";
   
    //在目录tmp_data中创建一个文件tmp.txt,并向其中写入一些内容
    if($fp = fopen($dir_name."/www.bkjia.com.txt",'a'))
    {
        if(fwrite($fp,"put some contenets into file."))
        {
            echo "


";
            echo "在目录".$dir_name."下创建文件tmp.txt";
        }
    }
}
else
{
    echo "创建目录失败!";
    exit;
}
echo "
";

 

if(rmdir($dir_name))    //尝试删除目录tmp_data
{
    echo "删除目录".$dir_name."成功!";
}
else
{
    echo "删除目录失败!";
    exit;
}

/*
总结:
创建目录就用mkdir有一点像dos里面的创建目录哦,方法很简单,关于删除目录,这里用了rmdir,但是只删除空目录,不能删除里面有文件或文件夹的目录,如果要删除不是空目录就要用递归来删除了/
*/


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!