PHP rmdir() Function

Definition and Usage

The rmdir() function deletes an empty directory.

If successful, the function returns true. If it fails, it returns false.

Syntax

rmdir(dir,context)
Parameter Description
dir Required. Specifies the directory to be deleted.
context Required. Specifies the environment of the file handle. Context is a set of options that modify the behavior of a modifiable stream.

Description

Attempt to delete dir The specified directory. This directory must be empty and have the appropriate permissions.

Tips and Notes

Note:on context support was added in PHP 5.0.0.

Example

<?php
$path = "images";
if(!rmdir($path))
  {
  echo ("Could not remove $path");
  }
?>