Note that there are some explanatory texts on larger screens.

plurals
  1. POGet immediate subdirectories in a directory on the server
    text
    copied!<p>I wrote a CMS in PHP. It works fine on most servers but I encountered a strange problem on my latest hosting account. This is either a path problem or a coding problem. The latter seems to be OK as this script works fine on all my other accounts, which is why I'm asking for help.</p> <p>When I first install my CMS tool I run a script called "inventory.php" in which I attempt to get and display all the directories on the server from the location of my script, which is 2 or 3 directories down from the root, depending on the server. I try to use a global path that goes up to the root and from it to return all the directories it can find. If this file works then the entire CMS works; if not... well that's why I'm here. </p> <p>Here's the code that scans the directories:</p> <pre><code>$main_root = realpath('../../'); echo '&lt;b style="color:orange;"&gt;All The dirs on this server:&lt;/b&gt;&lt;hr&gt;&lt;br&gt;'; $whats_on_the_server = array_filter(glob($main_root.'/*'), 'is_dir'); foreach($whats_on_the_server as $on_server) { $on_server = trim($on_server); if(stristr($on_server,'.')){ $arr1 = preg_split('^/^',$on_server); echo $arr1[4].'&lt;br&gt;'; } } </code></pre> <p>The root is: chroot/home/account/ under which all my folders are located. I can't run a script from that directory, so I must access it from elsewhere. This works fine on other servers but on the one I currently use, it doesn't return anything if the path is set as above. It gets the directory contents if I set the path to a subfolder on the specific server, such as:</p> <pre><code>$main_root = realpath('../../SomeDir'); </code></pre> <p>I must however get the name of all the directories located on the root.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload