# PHP script to read file names into Flash

**URL:** <https://forum.kirupa.com/t/php-script-to-read-file-names-into-flash/11646>\
**Category:** programming\
**Created:** [January 20, 2003, 4:41pm UTC](https://forum.kirupa.com/t/php-script-to-read-file-names-into-flash/11646 "2003-01-20T16:41:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrthad](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@andrthad](https://forum.kirupa.com/u/andrthad)\
**Post date:** [January 20, 2003, 4:41pm UTC](https://forum.kirupa.com/t/php-script-to-read-file-names-into-flash/11646/1 "2003-01-20T16:41:27Z")

</div>

Hi,

I was wondering if anybody could give me some direction on how to use PHP to read files names located in a server folder into Flash MX. Once in Flash MX I would like to read these file names into an array. A link, thread, tute, anything would be helpful.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 20, 2003, 10:37pm UTC](https://forum.kirupa.com/t/php-script-to-read-file-names-into-flash/11646/2 "2003-01-20T22:37:35Z")

</div>

```php
<?php
if ($dir = opendir("./")) {
  while (($file = readdir($dir)) !== false) {
    	$cont++;
	if ($file == "." || $file == "..") { } else {
    		$string.="file$cont=$file&";
		}
  	}
	closedir($dir);
}
$string.="status=OK";
print($string);
?>

```

save as listfiles.php , and you’re done…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 20, 2003, 11:32pm UTC](https://forum.kirupa.com/t/php-script-to-read-file-names-into-flash/11646/3 "2003-01-20T23:32:35Z")

</div>

Hi eyezberg,

Thank you for taking the time to answer this thread. Forgive my simple questions.

Just to further explain request. I have a website in a root folder. I have a music subfolder with a list of mp3s. I want to read this list of mp3 file names into an array (called songList) located in flash.

From the code you give below can I do something like this to get it into my array in Flash:

```auto

//frame action
loadVariablesNum("listfiles.php", 0);
songList = string; 

```

I am sure I am oversimplifying.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 21, 2003, 8:10am UTC](https://forum.kirupa.com/t/php-script-to-read-file-names-into-flash/11646/4 "2003-01-21T08:10:04Z")

</div>

Put the php file into your mp3 folder, then call it directly from your browser to see the output ([www.yoursite.com/mp3folder/listfiles.php](http://www.yoursite.com/mp3folder/listfiles.php))  
and work from there.  
Basically, you get file1=song.mp3&file2=anothersong.mp3&…&status=OK  
so you want to check on status variable to see if your load is finished, then you could loop thru the string and split it at &,  
so you get an array…  
All depends on how you set up your swf, and what info you want to display…alos have (somewhere) a php reading all files, sizes, extensions etc…  
let me know
