...

View Full Version : list mp3's only from a directory php



pagedrop
11-13-2011, 05:57 PM
looking for help to list mp3's only from a directory with php

forexample:

someonesong.mp3
title: somonesong

thank you in advance

Fou-Lu
11-13-2011, 06:03 PM
Use a glob.


$sPath = '/path/to/dir/*.mp3';
foreach (glob($sPath) AS $mp3)
{
print $mp3 . PHP_EOL;
}



Oh, and if you just want parts, use the pathinfo (http://php.ca/manual/en/function.pathinfo.php) function in PHP to pull apart the path.

pagedrop
11-13-2011, 07:24 PM
thank you for the reply.

it shows the mp3 well.

how can i integrate into format like this?

<li><a href="#" data-src=dir/somesong.mp3">song name only</a></li>

thank you

Adee
11-13-2011, 07:44 PM
thank you for the reply.

it shows the mp3 well.

how can i integrate into format like this?

<li><a href="#" data-src=dir/somesong.mp3">song name only</a></li>

thank you


$dir = '/path/to/dir/*.mp3';

foreach(glob($dir) as $mp3)
{
$k = pathinfo($mp3);
$m = $k['basename'];
$v = explode(".",$k['basename']);
echo "<li><a href='#' data-src='dir/".$m."'>".$v[0]."</a></li>";

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum