Hi everyone,
I'm hoping someone can help me here!
What I'm trying to do:
Loop through an uploaded file ( .m3u - playlist from Winamp) and add the contents to a database.
I'm having trouble parsing the .m3u file however. In the following code snippet it tries to display to the browser. If I can get it to display to the browser, I figure it will be easy to write it to the database!?
Here is my code snippet:
<?
// Convert seconds to minutes m:ss
function TimeFromSec($sec)
{
$minutes = floor(($sec % 3600) / 60);
$seconds = floor(($sec % 3600) % 60);
if(strlen($seconds) == 1)
{
$seconds = "0".$seconds;
}
return $minutes.":".$seconds;
}
// Open the file
$fd = fopen($_FILES['userfile']['name'], "r");
// Display the top of the table
?>
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#CCFFFF" width='500'>
<tr>
<td bgcolor="#000000"><font color="#99FFFF" face="Arial" size="-1">Artist</font></td>
<td bgcolor="#000000"><font color="#99FFFF" face="Arial" size="-1">Title</font></td>
<td bgcolor="#000000"><font color="#99FFFF" face="Arial" size="-1">Time</font></td>
</tr>
<?
//read the file line by line...
while (!feof($fd))
{
$buffer = fgets($fd);
//and parse it line by line...
if(ereg('#EXTINF:\([[:digit:]]+),([A-Z\' &^`~!@$%*,_]+) - ([A-Z\' &^`~!@$%*,_-]+)', $buffer, $reg))
{
//output the result
echo '<tr><td style="border-bottom:1px solid black; border-left:1px solid black">
<font face="Arial" size="-1">'.$reg[2].' </td><td style="border-bottom:1px
solid black"><font face="Arial" size="-1">'.$reg[3].'</td><td align = "center"
style="border-bottom:1px solid black; border-right:1px solid black">
<font face="Arial" size="-1">'.TimeFromSec($reg[1]).'</td></tr>';
}
}
//Close the file
fclose ($fd);
//Delete the file
unlink($realname);
?>
</table>
For reference, an .M3U file looks like this:
#EXTM3U
#EXTINF:272,Unknown Artist - Track 1
F:\Track01.cda
#EXTINF:252,Unknown Artist - Track 2
F:\Track02.cda
#EXTINF:237,Unknown Artist - Track 3
F:\Track03.cda
Any help, suggestions, etc would be greatly appreciated!
Thank you,
Dan