Skip to content

Instantly share code, notes, and snippets.

@hmschreiner
Created December 16, 2015 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmschreiner/0e0a6c7c4c7256c7ecb1 to your computer and use it in GitHub Desktop.
Save hmschreiner/0e0a6c7c4c7256c7ecb1 to your computer and use it in GitHub Desktop.
Recursive Directory Iteration for MP3 files
<?php
$path = realpath('/home/user/Music');
$ite = new RecursiveDirectoryIterator($path);
$files = array();
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) {
if($cur->isDir() || $cur->getExtension() != 'mp3') {
continue;
}
$files[] = array(
'name' => $cur->getFileName(),
'path' => $filename,
'extension' => $cur->getExtension(),
);
}
echo '<pre>';
print_r($files);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment