PHP | closedir( ) Function Last Updated : 11 Jul, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The closedir() function in PHP is an inbuilt function which is used to close a directory handle. The directory handle to be closed is sent as a parameter to the closedir() function and the closedir() closes the directory handle. The directory handle must be previously opened by the opendir() function. Syntax: closedir($dir_handle) Parameters Used: The closedir() function in PHP accepts only one parameter as described below. $dir_handle: It is an optional parameter which specifies the directory handle resource previously opened with opendir().If this parameter is not specified, the last link opened by opendir() is assumed and closed by closedir(). Return Value: It does not return any value. Errors And Exceptions: The directory handle sent as a parameter to the closedir() function must be previously opened by the opendir() function. If the dir_handle parameter is not specified, the last link opened by opendir() is assumed and closed by closedir() function. Below programs illustrate the closedir() function: Program 1: php <?php // Opening a directory $dir_handle = opendir("/user/gfg/docs/"); if(is_resource($dir_handle)) { echo("Directory Opened Successfully."); // closing the directory closedir($dir_handle); } else { echo("Directory Cannot Be Opened."); } ?> Output: Directory Opened Successfully. Program 2: php <?php // opening a directory and reading its contents $dir_handle = opendir("user/gfg/sample.docx"); if(is_resource($dir_handle)) { while(($file_name = readdir($dir_handle)) == true) { echo("File Name: " . $file_Name); echo "<br>" ; } // closing the directory closedir($dir_handle); } else { echo("Directory Cannot Be Opened."); } ?> Output: File Name: sample.docx Reference: http://php.net/manual/en/function.closedir.php Comment More infoAdvertise with us Next Article PHP end() Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-file-handling Practice Tags : Misc Similar Reads PHP fclose() Function The fclose() function in PHP closes a file that was previously opened by fopen(). Closing a file releases the resource associated with it and makes sure all the data written to the file is properly saved. Not closing files can lead to resource leaks or incomplete data writing.Syntax:bool fclose(reso 2 min read PHP finfo_close() Function The finfo_close() function is an inbuilt function in PHP that is used to close the file instance that is opened by the finfo_open() function. Syntax: finfo_close($finfo):Â boolParameters: This function accepts only one parameter which is described below. $finfo: The file info resource returned by fin 2 min read PHP | zip_close( ) Function The zip_close() function is an inbuilt function in PHP which is used to close a zip archive file opened by the zip_open() function. The zip_close() causes the stream to be closed and the connection to the corresponding Zip Archive to be broken. The zip resource which has been opened by the zip_open( 2 min read PHP end() Function The end() function is an inbuilt function in PHP and is used to find the last element of the given array. The end() function changes the internal pointer of an array to point to the last element and returns the value of the last element.Syntax:end($array)Parameters:This function accepts a single par 2 min read PHP | exit( ) Function The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message 2 min read PHP ereg() Function The Ereg() function in PHP searches a string to match the regular expression given in the pattern. The function is case-sensitive. This function has been deprecated in PHP 5.3.0 and removed in PHP 7.0.0. Syntax: int ereg ( string $pattern , string $str, array &$arr ); Parameters: pattern: It is 2 min read Like