w3resource logo


PHP Tutorial

PHP : readdir() function

Secondary Nav

Description

The readdir() function is used to read an entry from a directory handle opened by opendir() function.

Version

(PHP 4 and above)

Syntax

readdir(dir_handle) 

Parameter

Name Description Required /
Optional
Type
dir_handle Specified directory handle, previously open by opendir(). Required Resource.

Return value

The filename on success, or FALSE on failure.

Value Type : String.

Example :

<?php
$dir_name = opendir("test");
while (($file = readdir($dir_name)) !== false)
{
echo "filename: " . $file . "<br />";
}
closedir($dir_name)
?> 

View the example in the browser

See also

PHP Function Reference



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program