In this article, you will learn how to remove an empty folder in PHP. The rmdir() function in PHP removes an empty directory.
what is the syntax of the RMDIR function in php?
rmdir(dir, context)
Parameter | Description |
---|---|
dir | Required. Specifies the path to the directory to be removed |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream |
examples of the RMDIR function
Example 1. In this example, we remove “images” directory.
<?php
$path = "images";
if(!rmdir($path)) {
echo ("Could not remove $path");
}
?>