demo.simple.write.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  7. // //
  8. // /demo/demo.simple.write.php - part of getID3() //
  9. // Sample script showing basic syntax for writing tags //
  10. // see readme.txt for more details //
  11. // ///
  12. /////////////////////////////////////////////////////////////////
  13. die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
  14. $TextEncoding = 'UTF-8';
  15. require_once('../getid3/getid3.php');
  16. // Initialize getID3 engine
  17. $getID3 = new getID3;
  18. $getID3->setOption(array('encoding'=>$TextEncoding));
  19. require_once('../getid3/write.php');
  20. // Initialize getID3 tag-writing module
  21. $tagwriter = new getid3_writetags;
  22. //$tagwriter->filename = '/path/to/file.mp3';
  23. $tagwriter->filename = 'c:/file.mp3';
  24. //$tagwriter->tagformats = array('id3v1', 'id3v2.3');
  25. $tagwriter->tagformats = array('id3v2.3');
  26. // set various options (optional)
  27. $tagwriter->overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental)
  28. $tagwriter->remove_other_tags = false; // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is.
  29. $tagwriter->tag_encoding = $TextEncoding;
  30. $tagwriter->remove_other_tags = true;
  31. // populate data array
  32. $TagData = array(
  33. 'title' => array('My Song'),
  34. 'artist' => array('The Artist'),
  35. 'album' => array('Greatest Hits'),
  36. 'year' => array('2004'),
  37. 'genre' => array('Rock'),
  38. 'comment' => array('excellent!'),
  39. 'track_number' => array('04/16'),
  40. 'popularimeter' => array('email'=>'user@example.net', 'rating'=>128, 'data'=>0),
  41. 'unique_file_identifier' => array('ownerid'=>'user@example.net', 'data'=>md5(time())),
  42. );
  43. $tagwriter->tag_data = $TagData;
  44. // write tags
  45. if ($tagwriter->WriteTags()) {
  46. echo 'Successfully wrote tags<br>';
  47. if (!empty($tagwriter->warnings)) {
  48. echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
  49. }
  50. } else {
  51. echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
  52. }