PHP rmdir() | Remove Directory

The PHP rmdir() function is used when we need to delete or remove a directory. For example:

   $directory = "Documents";
   $ch = rmdir($directory);
      echo "<p>The directory deleted successfully</p>";
      echo "<p>Unable to delete the directory</p>";

The output of above PHP example on rmdir() function is shown in the following snapshot:

php rmdir function

Note - The directory will be removed only when the directory is completely empty.

The above output is produced because, inside my current directory, there is a folder/directory named Documents that was of course empty.

PHP rmdir() Syntax

The syntax of rmdir() function in PHP, is:

rmdir(directory, context)

The first (directory) parameter is required, whereas the last (context) parameter is optional, that is used to specify the context resource while removing an empty directory.

PHP Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube