php create directory and php delete directory code_PHP tutorial

WBOY
Release: 2016-07-20 11:01:27
Original
858 people have browsed it

To create a directory, use mkdir, which is a bit like creating a directory in dos. The method is very simple. Regarding deleting a directory, rmdir is used here, but only empty directories are deleted, and directories with files or folders in them cannot be deleted. If you want to delete a directory that is not empty, The directory needs to be deleted using recursion/ ​

php tutorial creating directory and php deleting directory code
/*
This is a tutorial article to tell you how to use php to create a directory and delete a directory. Let's take a look at an example of creating a directory. However, you need to have web permissions to create a directory.
*/

$dir_name = "www.bkjia.com";

if(mkdir($dir_name)) //Create directory tmp_data
in the current directory {
echo "Directory".$dir_name."Created successfully!";
 
//Create a file tmp.txt in the directory tmp_data and write some content into it
If($fp = fopen($dir_name."/www.bkjia.com.txt",'a'))
{
If(fwrite($fp,"put some contenets into file."))
           {
echo "


";
                  echo "Create file tmp.txt in directory ".$dir_name.";
}
}
}
else
{
echo "Failed to create directory!";
exit;
}
echo "
";

if(rmdir($dir_name)) //Try to delete the directory tmp_data
{
echo "Delete directory".$dir_name."Success!";
}
else
{
echo "Failed to delete directory!";
exit;
}

/*
Summary:
To create a directory, use mkdir, which is a bit like creating a directory in dos. The method is very simple. Regarding deleting a directory, rmdir is used here, but only empty directories are deleted, and directories with files or folders in them cannot be deleted. If you want to delete a directory that is not empty, The directory needs to be deleted using recursion/
*/


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445437.htmlTechArticleTo create a directory, use mkdir, which is a bit like creating a directory in dos. The method is very simple. Regarding deleting the directory, here I used rmdir, but only deleted empty directories, not files or files in them...
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