# Get a list of file names from directory using URLLoader and php

**URL:** https://forum.kirupa.com/t/get-a-list-of-file-names-from-directory-using-urlloader-and-php/328641
**Category:** Uncategorized
**Created:** [June 1, 2012, 4:09pm UTC](https://forum.kirupa.com/t/get-a-list-of-file-names-from-directory-using-urlloader-and-php/328641 "2012-06-01T16:09:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bonassus](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bonassus](https://forum.kirupa.com/u/bonassus)
#### Post date: [June 1, 2012, 4:09pm UTC](https://forum.kirupa.com/t/get-a-list-of-file-names-from-directory-using-urlloader-and-php/328641/1 "2012-06-01T16:09:05Z")

</div>

I hope this is the right place for this post. I am trying to trace a list of all file names in a directory using php. Unfortunately i don’t know how to use php and am trying to modify a code i found on the internet. any help would be appreciated.

My php code looks like this:

```auto

<?
   $dir = 'CastingSoundFiles/MissA';

   $dirHandle = opendir($dir);
   $count = -1;
   $returnstr = "";
   while ($file = readdir($dirHandle)) { 
      if(!is_dir($file) && strpos($file, '.mp3')>0) {
         $count++;
         $returnstr .= '&f'.$count.'='.$file;
      }
   } 
   $returnstr .= '&';
   echo $returnstr;
   closedir($dirHandle);
?>

```

and I’m loading it in flash like this:

```auto

package
{
    import flash.events.*
    import flash.net.*;
    public class GetFiles
    {
        var loader:URLLoader = new URLLoader();
        
        public function GetFiles()
        {
        
    
            loader.addEventListener(Event.COMPLETE, useData);
            loader.load(new URLRequest("readfromdir.php"));
        }
        
        
        
        function useData(event:Event):void {
            var data:String = event.target.data.toString();
            trace(data);
        }
        
        
    }
}

```

this just traces the php file. how do i run this php code to get the returnstr variable.

Thanks for help sorry im so confused.
