Detailed explanation of how to use the PHP rmdir() function

藏色散人
Release: 2023-04-05 22:16:01
Original
2501 people have browsed it

The rmdir() function in PHP is a built-in function used to delete empty directories. The directory must be empty, and you must have the relevant permissions required to delete the directory.

The directory to be deleted is sent to the rmdir() function as a parameter. If it succeeds, it will return True; if it fails, it will return False.

Syntax:

rmdir(dirname, context)
Copy after login

Usage of parameters:

The rmdir() function in PHP accepts two parameter.

dirname: It is a mandatory parameter that specifies the directory to be deleted.

context: It is an optional parameter that specifies the behavior of the stream.

Return value:

Returns True when successful and False when failed.

Errors and exceptions

1. The rmdir() function generates an E_WARNING level error when it fails.

2. Opendir() must be closed before using the rmdir() function, otherwise a permission denied error will be given.

3. PHP checks whether the directory where the script is running has the same UID (owner) as the script being executed in safe mode.

rmdir() function code example 1:

<?php 
// 创建一个名为gfg的目录
mkdir(&#39;gfg&#39;); 
$dirname= "gfg"; 
  
// 使用rmdir()删除目录
rmdir($dirname); 
?>
Copy after login

Output:

1
Copy after login

rmdir() function code example 2:

<?php 
// 创建一个名为gfg的目录
 $dirname = "gfg"; 
  
// 使用rmdir()删除目录
if(rmdir($dirname)) 
{ 
  echo ("$dirname已成功删除"); 
} 
else
{ 
 echo ($dirname . "不能被删除");  
} 
?>
Copy after login

Output:

gfg已成功删除
Copy after login

Related recommendations: "PHP Tutorial"

The above is the detailed content of Detailed explanation of how to use the PHP rmdir() function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!