Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to use opendir() function in php ?
The opendir() function is used to open a directory handle.
The opendir() function always returns a directory handle resource on succes and return FALSE on failure.
syntax of opendir() function
opendir(path,context);
path is a required parameter
context is a required optional
you can see below example:
<?php
//here define dir which die you want to read
$dir_name = "img";
// Open a directory, and read its contents
if (is_dir($dir_name)){
if ($getDir = opendir($dir_name)){
while (($file = readdir($getDir)) !== false){
//here print file file name
echo "filename:" . $file . "<br>";
}
}
}
?>
0 Comment(s)