get all file names from a directory in php
<p>(Well what I gone through a lot of posts here on stackoverflow and other sites. I need a simple task, )</p>

<p>I want to provide my user facility to click on upload file from his account, then select a directory and get the list of all the files names inside that directory.</p>

<p>According to the posts here what I got is I have to pre-define the directory name, which I want to avoid.</p>

<p>Is there a simple way to click a directory and get all the files names in an array in PHP? many thanks in advance!</p>

<pre><code>  $dir = isset($_POST['uploadFile']) ? _SERVER['DOCUMENT_ROOT'].'/'.$_POST['uploadFile'] : null;
  if ($_POST['uploadFile'] == true) 
    {
     foreach (glob($dir."/*.mp3") as $filename) {
     echo $filename;
    }
  }
</code></pre>
