# PHP Reading folders and files

**URL:** https://forum.kirupa.com/t/php-reading-folders-and-files/99898
**Category:** Uncategorized
**Created:** [January 23, 2004, 3:24pm UTC](https://forum.kirupa.com/t/php-reading-folders-and-files/99898 "2004-01-23T15:24:13Z")
**Posts on this page:** 1
**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 23, 2004, 3:24pm UTC](https://forum.kirupa.com/t/php-reading-folders-and-files/99898/1 "2004-01-23T15:24:13Z")

</div>

Hi All,

Disclaimer: PHP newbie

I’m using a similar piece of code to read all the files in a certain web server directory into a long variable text string. Then I use loadvars to import into Flash and read into an array.

```php

/* Returns the filenames from the directory */
<?
$dir = opendir("flash_1");
$i = 1;
while($file = readdir($dir))
if(is_file($file))
echo "&file". $i . "=" . $file;
?>

```

I understand the code above, but don’t know the objects/functions to use to read folder names in PHP. Instead of reading file names, I would like to read all of the folder names inside a folder. For example, how would I write a PHP loop to return all the artist name folders inside a folder called music?

music  
artist folder names (nested inside music folder)
