The following code reads a directory containing .mp3 files and gets their tag information such as Title, Genre etc and stores these in the WAMP database, however because its reading a directory and storing the files in an array, the values in the database are being shown as "array" for every column field but I want the values for each file to show. Does anyone know how I can correct my code in order for this to happen, thanks!
my code:
$sDir = 'mp3/';
$aFiles = array();
$rDir = opendir($sDir);
if ($rDir) {
while ($sFile = readdir($rDir)) {
if ($sFile == '.' or $sFile == '..' or !is_file($sDir . $sFile))
continue;
$aPathInfo = pathinfo($sFile);
$sExt = strtolower($aPathInfo['extension']);
if ($sExt == 'mp3') {
$aFiles[] = $sDir . $sFile;
}
}
closedir($rDir);
}
// new object of our ID3TagsReader class
$oReader = new ID3TagsReader();
// passing through located files ..
$sList = $sList2 = '';
foreach ($aFiles as $sSingleFile) {
$Title = $oReader->getTagsInfo($sSingleFile); // obtaining ID3 tags info
$Author = $oReader->getTagsInfo($sSingleFile);
$AlbumAuthor = $oReader->getTagsInfo($sSingleFile);
$Year = $oReader->getTagsInfo($sSingleFile);
$Genre = $oReader->getTagsInfo($sSingleFile);
$sList .= '<tr><td>'.$Title['Title'].'</td><td>'.$Author['Author'].'</td><td>'.$AlbumAuthor['AlbumAuthor'].'</td>
<td>'.$Year['Year'].'</td><td>'.$Genre['Genre'].'</td></tr>';
$dbhost = "localhost";
$dbname = "project";
$dbusername = "root";
$dbpassword = "";
$link = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
$statement = $link->prepare("INSERT INTO mp3(Title, Author, AlbumAuthor, Year, Genre)
VALUES(:Title, :Author, :AlbumAuthor, :Year, :Genre)");
$statement->execute(array(
"Title" => "$Title",
"Author" => "$Author",
"AlbumAuthor" => "$AlbumAuthor",
"Year" => "$Year",
"Genre" => "$Genre"
));