pcw Posted March 12, 2009 Share Posted March 12, 2009 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 Link to comment https://forums.phpfreaks.com/topic/149139-solved-listing-directory-folders-and-files-in-a-select-menu/ Share on other sites More sharing options...
pcw Posted March 12, 2009 Author Share Posted March 12, 2009 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(); ?> Link to comment https://forums.phpfreaks.com/topic/149139-solved-listing-directory-folders-and-files-in-a-select-menu/#findComment-783149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.