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
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";
  }
}

Link to comment
Share on other sites

 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.