Listing directory on a server using php
<p>I need to list a set directories on server using a php script that is also on the server. Here is my folder structure on the server: (ftp)</p>
<p><img src="https://i.stack.imgur.com/08mjW.png" alt="1" /></p>
<p>and this is the code that is written in listDirectory.php (I need to know what are the sub-directories of /public_html/stickers/ and how many file exist in each of those sub-directory) I know i can hard-code it but i need a dynamic approach as the files will change a lot.</p>
<pre><code>&lt;html&gt;
&lt;title&gt;Directories&lt;/title&gt;
&lt;body&gt;
    &lt;?php
        $directory = $_SERVER['DOCUMENT_ROOT'] . '/stickers/';
        echo &quot;&lt;p&gt;$directory&lt;/p&gt;&quot;;
        
        $sticker_directories =  array(scandir($directory));
        
        echo &quot;&lt;p&gt;Number of subdirs at $directory :&quot;. count($sticker_directorie) . &quot;&lt;/p&gt;&quot;;
        
        foreach ($sticker_directories as $dir){
            $working_dir = $directory.$dir;
            echo &quot;&lt;p&gt;$working_dir&lt;/p&gt;&quot;; 
            if (is_dir($working_dir)){
                
                echo &quot;&lt;p&gt;$working_dir&quot; . count(scandir($working_dir)) . &quot;&lt;/p&gt;&quot;;
            }
        }   
    ?&gt;
&lt;/body&gt;
&lt;/html&gt; 
</code></pre>
<p>and this is the output:</p>
<pre><code>/home/u826063014/public_html/stickers/

Number of subdirs at /home/u826063014/public_html/stickers/ :0

/home/u826063014/public_html/stickers/Array
</code></pre>
<p>Which is not the result i was expecting. what am i doing wrong?</p>
<p>(I'm totally new to all this)</p>