Jump to content

[SOLVED] listing directory folders and files in a select menu


pcw

Recommended Posts

Hi, I am trying to create a template modify page. I have got two forms so far, the first one works fine and the dropdown menu lists the folders in the specified directory.

 

Once a user has selected a folder from the menu and clicked submit, I want it to show another dropdown menu, but this one showing the files in the selecte folder.

 

Thats the bit that doesnt work, it keeps coming up with errors and I cant see what I am doing wrong. Any help much appreciated.

 

<?php

include("../../addons.php");

function edit_temp() {

adminheader();

$directory = "../../templates/";
$handle = opendir($directory);
while ($folder = readdir($handle))
{
$folders[] = $folder;
}
closedir($handle);
sort($folders);
print "<form method='POST'>";
print "<select name='temp_folder'>";
Print "<option>Choose folder</option>";
foreach ($folders as $folder) {
if (($folder != ".") And ($folder != "..")) {
print sprintf("<option value='templates/%s'>%s</option>", $folder, $folder);
}
}
print "</select>";
print "<input type='submit' name='tmpsubmit' value='submit'>";
print "</form>";

if($_POST = 'tmpsubmit') {

$tmp_folder = $_POST['temp_folder'];
$con_fold = "../../templates/$tmp_folder/";
$handle1 = opendir($con_fold);
while ($file = readdir($handle1))
{
$files[] = $file;
}
closedir($handle1);
sort($files);
print "<form method='POST'>";
print "<select name='temp_name'>";
Print "<option>Choose template</option>";
foreach ($files as $file) {
if (($file != ".") And ($file != "..")) {
print sprintf("<option value='$con_fold/%s'>%s</option>", $file, $file);
}
}
print "</select>";
print "<input type='submit' name='tmpsubmit' value='submit'>";
print "</form>";
}

adminfooter();
}
edit_temp();
?>

 

Thanks

Its ok, fixed it:

 

<?php

include("../../addons.php");

function edit_temp() {

adminheader();

$directory = "../../templates/";
$handle = opendir($directory);
while ($folder = readdir($handle))
{
$folders[] = $folder;
}
closedir($handle);
sort($folders);
print "<form method='POST'>";
print "<select name='temp_folder'>";
Print "<option>Choose folder</option>";
foreach ($folders as $folder) {
if (($folder != ".") And ($folder != "..")) {
print sprintf("<option value='$directory/%s'>%s</option>", $folder, $folder);
}
}
print "</select>";
print "<input type='submit' name='tmpsubmit' value='submit'>";
print "</form>";


$tmp_folder = $_POST['temp_folder'];
$con_fold = "$tmp_folder";
$handle1 = opendir($con_fold);
while ($file = readdir($handle1))
{
$files[] = $file;
}
closedir($handle1);
sort($files);
print "<form method='POST'>";
print "<select name='temp_name'>";
Print "<option>Choose template</option>";
foreach ($files as $file) {
if (($file != ".") And ($file != "..")) {
print sprintf("<option value='$con_fold/%s'>%s</option>", $file, $file);
}
}
print "</select>";
print "<input type='submit' name='tmpsubmit' value='submit'>";
print "</form>";
}

adminfooter();

edit_temp();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.