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/
*/