project3 Posted April 17, 2008 Share Posted April 17, 2008 I have some code to list files in a dir but i only want to list mp3s as there are image files in it too. heres the code i have it works but i want to only do mp3 extension. if (!is_dir("$dirpath/$file")) { $buildhtml .= "<option value=$file>$file</option>"; } } closedir($dlist); thanks in advance! Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 17, 2008 Share Posted April 17, 2008 If you use the glob() function, you can specify a pattern for the file name to retrieve from a given directory: <?php foreach(glob('path/to/files/*.mp3') as $v ){ echo $v.'<br />'; } ?> Quote Link to comment Share on other sites More sharing options...
project3 Posted April 17, 2008 Author Share Posted April 17, 2008 If you use the glob() function, you can specify a pattern for the file name to retrieve from a given directory: <?php foreach(glob('path/to/files/*.mp3') as $v ){ echo $v.'<br />'; } ?> thats prints out the path also i only need the file name. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 17, 2008 Share Posted April 17, 2008 Use the basename() function: <?php foreach(glob('path/to/files/*.mp3') as $v ){ echo basename($v).'<br />'; } ?> If you don't want the extension either, then use basename($v,'.mp3') Quote Link to comment Share on other sites More sharing options...
project3 Posted April 17, 2008 Author Share Posted April 17, 2008 Use the basename() function: <?php foreach(glob('path/to/files/*.mp3') as $v ){ echo basename($v).'<br />'; } ?> If you don't want the extension either, then use basename($v,'.mp3') Thanks worked perfect! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.