Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to use readdir() function in php ?
The readdir() function is used for returning the name of the next entry in a directory.
This function returns the filename on success and return FALSE on failure.
syntax of readdir() function
readdir(dir_handle);
dir_handle is a optional parameter
you van see below example:
<?php
//here define dir which die you want to read
$dir = "img";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($getDir = opendir($dir)){
while (($file = readdir($getDir)) !== false){
//here print file file name
echo "filename:" . $file . "<br>";
}
//here close dir
closedir($getDir);
}
}
?>
The output of the code above will be:
filename:zoom-out.png
filename:4.png
filename:zoom-in.png
filename:edit.png
filename:delete.png
0 Comment(s)