What are some methods in PHP to read all files in a specific directory and output them in a selection menu?
To read all files in a specific directory and output them in a selection menu in PHP, you can use the glob() function to retrieve an array of file names in the directory. Then, loop through the array and create an HTML select menu with the file names as options.
$directory = "path/to/directory/";
$files = glob($directory . "*");
echo "<select>";
foreach ($files as $file) {
$fileName = basename($file);
echo "<option value='$fileName'>$fileName</option>";
}
echo "</select>";
Related questions
-
if-else statements PHP code snippet
-
variable passing variable manipulation PHP documents
-
PHP meta tags headers