First off, I am totally new to PHP, but so far i love the possibilities i have seen with it.
Ok, heres my problem. I have a script that will automatically scan a folder and show me the file names of that folder in a drop-down menu.
<?php
$dirname = "logs";
$dir = opendir($dirname);
echo '<select name="file2">';
echo '<option value="">Logfiles</option>';
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
echo "<option value=".$file.">$file</option>";
}
}
echo '</select>';
?>
So far so good, that part works just fine.
I then have a piece of code that would show me the contents of a chosen file.
<?php
$content = file("filenamehere");
$data = implode("<br>",$content);
echo $data;
?>
This part on its own also works fine.
I now want to combine these 2 scripts. This is where i get totally lost. I have tried all various combinations of which variable to put as a “filenamehere”, but I only get as far as having my choice from the drop-down echoing the chosen filename in the drop-down button. I have not been able to actually get the 2nd part of the code to display the file contents of the file I have chosen. I tried things like (“$file”) for the $content variable but nothing happens.
Of course any other single script solution would also be great. I just need to be able to scan a folder, have its files listed in a drop-down, and once i choose a file i want it to be displayed on the page.
Any help would be deeply appreciated since im a total beginner in PHP.
Cheers.
Am assuming you are doing everything in a single page. I have wrapped a
formtag around theselectdropdown and added a submit buttonThe second part
Hope this helps