Overbleed Posted November 5, 2010 Share Posted November 5, 2010 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 More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 Can you post the code you tried so far to generate and populate the list? Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130805 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 $ourDir = "../templates"; $ourDirList = @opendir($ourDir); while ($ourItem = readdir($ourDirList)) { if (is_dir($ourItem)) { echo "directory: $ourItem "; } if (is_file($ourItem)) { echo "file: $ourItem"; } } closedir($ourDirList); Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130810 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 What's the output of just: $ourDir = "../templates"; $ourDirList = @opendir($ourDir); while ($ourItem = readdir($ourDirList)) { echo $ourItem; } Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130818 Share on other sites More sharing options...
rwwd Posted November 5, 2010 Share Posted November 5, 2010 $ourDirList = @opendir($ourDir); Seriously: @ <-- why use the error suppressor, you want to know what's wrong, php only recommend that you use the @ on certain xml functions. Rw Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130820 Share on other sites More sharing options...
AbraCadaver Posted November 5, 2010 Share Posted November 5, 2010 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 https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130822 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 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 https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130824 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 Does it change if you have a slash after: $ourDir = "../templates" like $ourDir = "../templates/" Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130825 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 If I put a trailing slash, nothing comes up. Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130827 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 Would you mind running this script please? What's the output: <?php $dir = '../templates'; $files1 = scandir($dir); print_r($files1); ?> Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130828 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 There is no output. Here is my structure, incase it helps. MAIN FOLDER - admin/ -- _inc/ - modules/ - libs/ - templates/ -- templates/default -- templates/_admin index.php Im calling this from my admin _inc folder. Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130829 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 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 https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130830 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 I'm developing locally. Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130831 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 Oh! I had an error in that code you posted eariler. The output of that is: Array ( [0] => . [1] => .. [2] => _admin [3] => default ) Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130832 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 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 https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130833 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 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 https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130834 Share on other sites More sharing options...
AbraCadaver Posted November 5, 2010 Share Posted November 5, 2010 $ourDir = "../../templates"; Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130836 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 AbraCadaver, oh man.. i missed that one! just looked back at his dir structure... hope that solves it. Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130837 Share on other sites More sharing options...
Overbleed Posted November 5, 2010 Author Share Posted November 5, 2010 That's the first thing I tried before posting lol. Doesn't make a difference. Nothing shows. Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1130838 Share on other sites More sharing options...
Overbleed Posted November 6, 2010 Author Share Posted November 6, 2010 Anyone know what to do here? Link to comment https://forums.phpfreaks.com/topic/217874-listing-directorys-into-an-html-menu/#findComment-1131138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.