title: Flatten recursive folder structure in PHP for mysql dbase
body: <p>Perhaps there's a better method than the PHP route, I am open to ideas.</p>
  
  <p>The problem: I have a folder structure for each user. This folder may contain files or sub-folders. I am only concerned with the folders which have files. I am able to run a query and get a recursive listing on a multidimensional array (from PHP code posted on the web). The issue is that I get a multidimensional array that when flattened only lists the inner most file name, and I need to store the path and file -or- the path+file in my sql dbase. The idea is to allow the user to view his files and delete them using a web interface. </p>
  
  <p>Here is an example result from the PHP recursive function. Inside a folder named "Jimmy", you find:</p>
  
  <pre><code>Array
  (
  [0] =&gt; info.txt
  [1] =&gt; log.tmp
  [2] =&gt; README.md
  [css] =&gt; Array
      (
          [0] =&gt; style.css
      )
  
  [images] =&gt; Array
      (
          [0] =&gt; flower.gif
      )
  [3] =&gt; index.php
  [testDir] =&gt; Array
      (
          [anotherTestDir] =&gt; Array
              (
                  [0] =&gt; test2.php
              )
  
      )
  [5] =&gt; listing.txt
  [temp] =&gt; Array
      (
      )
  
  )
  </code></pre>
  
  <p>What I'd wold like to see is this:</p>
  
  <pre><code>/jimmy/info.txt
  /jimmy/log.tmp
  /jimmy/README.md
  /jimmy/css/style.css
  /jimmy/images/flower.gif
  /jimmy/index.php
  /jimmy/testDir/anotherTestDir/test2.php
  /jimmy/listing.txt
  </code></pre>
  
  <p>And then I would need to sort the string and add it to mysql dbase. Any help on how to achieve this effect would be much appreciated. Once I have my flatten array i want to add it in one go to the user's "folder" table.</p>