Basic php, dropdown and functions question

Associate
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
I am a complete novice to php, scripting and html. I am trying to dynamically generate a dropdown box with a list of folders and then I want to generate a list links to the files for the selected folders. I have been searching for the solution which I am sure is really obvious but I don't full understand the code structure

I have this to generate the dropdown box and populate with the folders in the "Docs\" directory

Code:
<!DOCTYPE html>
<html>
<body>

<select id="mySelect" >

<?php
    $dirs = glob("Docs\*", GLOB_ONLYDIR);
    foreach($dirs as $val)
    {
    echo '<option value="'.$val.'">'.basename($val)."</option>\n";
    }   
?>  

</select>
</body>
</html>

I also have this to generate links from a set folder

Code:
<!DOCTYPE html>
<html>
<body>


<?php
foreach (glob("Docs\PB02\*.pdf") as $pathtodocs)
    {
    $filename = basename($pathtodocs);
    echo "<a href=\"$pathtodocs\">$filename</a>";
    echo "<br>";
    } 
?>

</body>
</html>
What I don't understand is how to call the second set of code as a function based on the first set of code and have it display underneath the drop down box. I have tried with onchange but as I say, I must be missing something basic
 
Associate
OP
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
thanks. I have been struggling with $_GET and $_POST.

This isn't quite working. Is there a way I can get it to echo the output og the $_GET statement so I can see what is happening?
 
Associate
OP
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
got it! it was going for docs\docs\foldername

Code:
<!DOCTYPE html>
<html>

<body>
    <form action="" method="GET">
        <select id="directories" name="directory" onchange="this.form.submit()">
		<option value="Select">Select Folder</option>;
            <?PHP
            $dirs=glob("Docs\\*", GLOB_ONLYDIR);
            foreach($dirs as $val) {
                echo '<option value="' . $val . '">' . basename($val) . "</option>"; 
            } 
            ?>
        </select>

		<p>
        <?PHP
        if(isset($_GET["directory"])) {
            foreach(glob($_GET["directory"] . "\\*.pdf") as $file) {
                echo '<a href="' . $file . '">' . basename($file) . '</a>';
				echo "<br>";
            }
        }
        ?>
		</p>
    </form>
</body>

</html>

Thankyou so much for your help
 
Back
Top Bottom