Fijiannn Posted January 6, 2014 Share Posted January 6, 2014 Hi I have this code below. What I'm trying to do below is access .mp3 songs that are in my folder called "songs" When I do this code it doesn't show anything for the Artist, Title or anything anymore. Why is that? <?php require_once('/home/manveers94/public_html/getID3-1.9.7/getid3/getid3.php'); $getID3 = new getID3; $SongsFolder = "songs"; $file = glob($SongsFolder."/*.mp3"); // $file = 'Song.mp3' set_time_limit(30); $ThisFileInfo = $getID3->analyze($file); getid3_lib::CopyTagsToComments($ThisFileInfo); echo 'File name: '.$ThisFileInfo['filenamepath'].'<br>'; echo 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : ' ').'<br>'; echo 'Title: '.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'<br>'; echo 'Bitrate: '.(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : ' ').'<br>'; echo 'Play time: '.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'<br>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/285125-mp3-in-folder/ Share on other sites More sharing options...
requinix Posted January 6, 2014 Share Posted January 6, 2014 $file is an array of filenames, not a single filename. You have to loop over it. Quote Link to comment https://forums.phpfreaks.com/topic/285125-mp3-in-folder/#findComment-1464016 Share on other sites More sharing options...
jazzman1 Posted January 6, 2014 Share Posted January 6, 2014 (edited) Check for actual errors, also. Put next functions on the top of this file: ini_set('display_errors',1); ini_set('display_startup_errors',1); ini_set('output_buffering','Off'); error_reporting(-1); Edited January 6, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285125-mp3-in-folder/#findComment-1464017 Share on other sites More sharing options...
Fijiannn Posted January 6, 2014 Author Share Posted January 6, 2014 $file is an array of filenames, not a single filename. You have to loop over it. $file is an array of filenames, not a single filename. You have to loop over it. I tried looping and getting these errors. Warning: pathinfo() expects parameter 1 to be string, array given in /home/manveers94/public_html/yee/Test.php on line 16 Notice: Undefined index: filenamepath in /home/manveers94/public_html/yee/Test.php on line 25 <?php ini_set('display_errors',1); ini_set('display_startup_errors',1); ini_set('output_buffering','Off'); error_reporting(-1); require_once('/home/manveers94/public_html/getID3-1.9.7/getid3/getid3.php'); $getID3 = new getID3; $SongsFolder = "songs"; $file = glob($SongsFolder."/*.mp3"); foreach($file as $SongPath) { $SongPath = pathinfo($file); } // $file = 'Song.mp3' set_time_limit(30); $ThisFileInfo = $getID3->analyze($SongPath); getid3_lib::CopyTagsToComments($ThisFileInfo); echo 'File name: '.$ThisFileInfo['filenamepath'].'<br>'; echo 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : ' ').'<br>'; echo 'Title: '.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'<br>'; echo 'Bitrate: '.(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : ' ').'<br>'; echo 'Play time: '.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'<br>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/285125-mp3-in-folder/#findComment-1464018 Share on other sites More sharing options...
TinyI Posted January 6, 2014 Share Posted January 6, 2014 (edited) Hey, In your foreach, your pathinfo is still looking at $file instead of $SongPath, meaning you're still looking at the array rather than a string. Change your foreach to foreach($file AS $filename) { $SongPath = pathinfo($filename); }Then it should work as expected. Note that you don't need to change the whole foreach, you could just change pathinfo($file) to pathinfo($SongPath). I suggested changing the foreach just to name your variables a bit better. Why are you looping through it just to get a path and not doing any other code inside the foreach? You know that you'll only ever get the last element in the array? Unless that's your intended behaviour, you should look at maybe using something like pathinfo($file[0]) instead of foreaching if you only ever want the first one. Edited January 6, 2014 by TinyI Quote Link to comment https://forums.phpfreaks.com/topic/285125-mp3-in-folder/#findComment-1464037 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.