PHP opendir() Function – Open Directory

Open Directory in PHP – opendir() Function

The opendir() function is used to open files from directory.

opendir() function syntax


$dir = opendir(“directory_name”);


opendir() function Example




Here, we use opendir() function to open directory “meera” and store in $dir variable, we use the $dir variable for read content of file in future.

Read files from directory using readdir() function and opendir() function.

Exmaple of readdir() in PHP

<title>Read Diretory in PHP</title>
<FORM method="POST">
Enter Directory Name : <input type="text" name="str"> <br/> <br/>
<input type="submit" name="Submit1" value="Read Files">

echo $file ."<br/>";

The output is :

PHP read directory
PHP readdir function example for read files from directory.

Leave a Reply

Your email address will not be published. Required fields are marked *