Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. /*
  3.  * Author : ShubhaM
  4.  * Posted at http://www.w3tools.info/2012/02/php-function-to-edit-mp3-tags.html
  5.  * Visit for more.
  6. */
  7.  
  8. /* Prepare an array that holds tag info */
  9.  
  10. $data = array(
  11. "mp3_songname" => "", // Song's name. Leave this blank to keep original song name
  12. "mp3_artist" => "w3tools",// Artist's name.
  13. "mp3_album" => "w3tools", // Album's name.
  14. "mp3_year" => "2011", // Song's year.
  15. "mp3_genre" => "w3tools", // Genre.
  16. "mp3_comment" => "Visit w3tools.info ", // Some comment on song.
  17. "mp3_image" => array(
  18.     "path" => "../albumart.jpg", // Albumart image must be present at this path.
  19.     "type" => "image/jpeg", // Albumart image's mime type.
  20.     "name" => "albumart.jpg" // Albumart image's name.
  21.     )
  22. );
  23.  
  24. /* The function for mp3 tag processing */
  25. function write_tags($mp3_file,$data=""){
  26.     if(!is_file($mp3_file))return false;
  27.     $mp3_tagformat = 'UTF-8';
  28.     require_once('getid3/getid3.php');
  29.     $mp3_handler = new getID3;
  30.     $mp3_handler->setOption(array('encoding'=>$mp3_tagformat));
  31.     require_once('getid3/write.php');
  32.     $mp3_writter = new getid3_writetags;
  33.     $mp3_writter->filename       = $mp3_file;
  34.     $mp3_writter->tagformats     = array('id3v1', 'id3v2.3');
  35.     $mp3_writter->overwrite_tags = true;
  36.     $mp3_writter->tag_encoding   = $mp3_tagformat;
  37.     $mp3_writter->remove_other_tags = false;
  38.  
  39.     $mp3_data['title'][]   = $data['mp3_songname'];
  40.     $mp3_data['artist'][]  = $data['mp3_artist'];
  41.     $mp3_data['album'][]   = $data['mp3_album'];
  42.     $mp3_data['year'][]    = $data['mp3_year'];
  43.     $mp3_data['genre'][]   = $data['mp3_genre'];
  44.     $mp3_data['comment'][] = $data['mp3_comment'];
  45.  
  46.         $mp3_data['attached_picture'][0]['data'] = file_get_contents($data['mp3_image']['path']);
  47.         $mp3_data['attached_picture'][0]['picturetypeid'] = $data['mp3_image']['type'];
  48.         $mp3_data['attached_picture'][0]['description'] = $data['mp3_image']['name'];
  49.         $mp3_data['attached_picture'][0]['mime'] = $data['mp3_image']['type'];
  50.  
  51.         $mp3_writter->tag_data = $mp3_data;
  52.         $mp3_writter->WriteTags();
  53. }
  54. /* End of function */
  55.  
  56. /* Call the function */
  57. write_tags("../my_song.mp3",$data);
  58. ?>