PHP readdir() directory function
Read files from directory in PHP.
The readdir() function is used to read files from directory in PHP.
readdir() function syntax
<?php
$file=readdir(“directory_name”);
?>
Example of readdir() in PHP
<HTML>
<head>
<title>Read Directory in PHP</title>
</head>
<body>
<FORM method="POST">
Enter Directory Name : <input type="text" name="str"> <br/> <br/>
<input type="submit" name="Submit1" value="Read Files">
</FORM>
<?php
if(isset($_POST["Submit1"]))
{
$dir=opendir($_POST["str"]);
while($file=readdir($dir))
{
echo $file ."<br/>";
}
}
?>
</body>
</HTML>
The output of read directory php function example is :