How to close directory in php

青灯夜游
Release: 2023-03-15 20:16:01
Original
2083 people have browsed it

In PHP, you can use the closedir() function to close the directory. The function of this function is to close the opened directory handle. It accepts an optional parameter to specify the directory path that needs to be closed. If it is omitted, Use the last url link opened by opendir(); the syntax is "closedir (directory path)".

How to close directory in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use closedir () function to close the directory.

The closedir() function can close an open directory handle and accepts an optional parameter:

closedir(dir_handle);
Copy after login
Parameter Description
dir_handleOptional. Specifies a directory handle resource previously opened by opendir(). If this parameter is not specified, the last link opened by opendir() is used.

Example: Open a directory using opendir(), read its contents, then close it using closedir()

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$dir = "img/";
// 打开一个目录,并读取其内容
if (is_dir($dir)) {
	if ($dh = opendir($dir)) {
		while (($file = readdir($dh)) !== false) {
			echo "文件名:" . $file . "<br>";
		}
		closedir($dh);
	}
}
?>
Copy after login

How to close directory in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to close directory in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!