Jump to content

Listing directorys into an HTML menu?


Overbleed

Recommended Posts

Hello, I'm building a CMS and I'm stuck on this little tiny part of my script.

 

I want to output the names of the templates into an HTML menu... I've tried a bunch of different scripts and opendir() but nothing works, can someone show me how I would do this?

 

The users put their templates in a folder "templates", so its "templates/USERSTEMPLATE/"

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/
Share on other sites

Yes, don't use @, also turn on error reporting.  Try this:

 

error_reporting(E_ALL);
ini_set('display_errors', '1');

$ourDir = "../templates";

foreach (glob($ourDir) as $ourItem)
{
  if (is_dir($ourItem))
  {
    echo "directory: $ourItem";
  } else {
    echo "file: $ourItem";
  }
}

 error_reporting(E_ALL);
ini_set('display_errors', '1');

$ourDir = "../templates";

echo '<select>';

foreach (glob($ourDir) as $ourItem)
{
  if (is_dir($ourItem))
  {
    echo " <option value='test'>$ourItem</option>";
  }

} 
echo '</select>';?>

 

I get the drop down menu, but the option simply says "../templates", no errors poped up either.

 

I have two templates in the templates folder, under "admin" and "default", and it's showing neither.

Hmmm.. could be folder permission issues, but you should be using this (as noted by a previous poster):

 

 error_reporting(E_ALL);
ini_set('display_errors', '1');

 

On all testing you do.. These errors will give you correct insight in your problems. You say no errors are being generated? Are you developing locally or on a hosting server? And it's possible your php.ini might need to be tweaked for directory reading.. Could be a lot simpler than that, but just shooting in the dark right now.

Oh!

 

I had an error in that code you posted eariler.

 

The output of that is:

 

Array ( [0] => . [1] => .. [2] => _admin [3] => default )

 

That's not an error. Thats array output of the directory! That's good news for you.. The directory is being read.. Now you can 1) either read your directories into an array OR 2) use your original script (just try this to see what happens) and use single quotes for your ourDir var.. see if that changes anything.

I know that's the output ;p I ment error as in I had a "\" in there when I hit enter.

 

I tried my original script with single quotes and it didnt change anything.

 

By the way, I'm doing this so the user can add a template to a new folder, I'm not sure if new folders being added will change anything.

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.