Php How To Get List Of All Filenames From A Folder

Php How To Get All Files Names From A Folder


________________________________________________________


In this Php Tutorial we will see How To Retrieve All Files Names In A Directory Using Php .

I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .



 




Php Source Code:

<?php

$dir_path = "folder/";
$options = "";
if(is_dir($dir_path))
{
    $files = opendir($dir_path);
    {
        if($files)
        {
          while(($file_name = readdir($files)) !== FALSE)
          {
              if($file_name != '.' && $file_name != '..')
              {
               // select option with files names
               $options = $options."<option>$file_name</option>";   
               
               // display the file names
               echo $file_name."<br>";
              }
          }
        }
}
}

?>


<!DOCTYPE html>
<html>
    <head>
        
    <title>PHP GET List Of FILES NAMES FROM A Directory </title>
    </head>
    
    <body>
        
        <select>
            <?php echo $options;?>
        </select>
        
    </body>
</html>


php files names




                     

Share this

Related Posts

Previous
Next Post »