Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a dropdown box with folders in directory

Status
Not open for further replies.

rjseals

Technical User
Nov 25, 2002
63
US
Hello all,
I am running into a little trouble with my currect project. I am a webadmin for a school district. I am using php and apache on a netware server. I have several different schools and within each school I have several different folders that contain teachers websites. So basically each folder is the teacher's username (ssmith etc). Instead of adding code each time a new teacher wants to build a website I thought I would create some code that would populate a dropdown box on the school index with the username's of the teacher folders within the main school directory.

Basically all I want the option of doing is choosing selecting the teacher's website to go to from a dropdown list. This is what I have so far.

html....

Code:
<select name = yes>
        <?
$dir = "/path/to/school/site/";  //sets directory path
   
   
      // Open a known directory, and proceed to read its contents
	   
    
if (is_dir($dir))
{  
    if ($dh = opendir($dir)) 
   {
        while (($file = readdir($dh)) !== false) //while files and folders are being read   
      {     
		     if (filetype($dir . $file) == dir) //if the filetype is a directory and not a file 
         {
			 
    echo '<option value="'.$file.'">',
         $file, '</option>';
         }
      }
        closedir($dh);
   }
}
?>
</select>
<input type="submit" value="Edit">

This code fills the list box just fine with the user names but I am at a loss as to how to proceed at forwarding the user on to the teacher's website. All I would need to do is add www.myschool.com/schools/site/username/ onto the end of the existing url because I am making the teachers have an index file.

Can anyone give me any pointers on how to procede?

Thanks.
 
disregard this statement <input type="submit" value="Edit">

I was just playing with passing the value along to another page.
 
At the top of the page
Code:
$url = '[URL unfurl="true"]http://domain.org/path/to/school/site/';[/URL]  
if (isset($_POST['yes'])) {
  $redirect = $url.$_POST['yes'].'index.php';
}

then where ever you output your html header check for the existance of $redirect and redirect the user
Code:
<html>
<head>
<?php
//selection made, redirect to new page
if (isset($redirect)) {
   echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$redirect.'">';
//Note the double qoutes in the META tag are required
}
?>
</head>
<body>...your page/code/form

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top