PHP closedir Function – Closing Directory Handles
The PHP closedir function closes a directory handle opened by opendir, accepting a resource parameter and returning TRUE on success or FALSE on failure, with usage examples and parameter details for backend filesystem operations.
The closedir function in PHP closes an opened directory handle, which must have been obtained via opendir(). It takes a resource parameter $dir_handle and returns TRUE on success or FALSE on failure.
Parameters $dir_handle – the directory stream resource opened by opendir(). If omitted, the most recently opened handle is assumed.
Return value
Returns TRUE on success, FALSE on error.
Example
<?php
$dir = "/etc/php7/";
// Open a known directory, read directory into variable and then close
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$directory = readdir($dh);
closedir($dh);
}
}
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
