Writing .mp3 tags with getID3() - PHP 7.2.31

1.1k Views Asked by At

I'm trying to write metatags for .mp3 files that don't have them. Using http://getid3.sourceforge.net/, I can analyse files, but when I try to write a tag I'm getting:

Failed to write tags! Tag format "Track Title" is not allowed on "mp3.mp3"

Has anyone been successful in writing mp3 meta tags?

EDIT: I had a mistake in the $tagwriter->tagformats which is now fixed. The code now "successfully writes tags" but the new tag "Track Title" tag is not present in the $info = $getID3->analyze($filepath);...

<?php

require_once 'getid3/getid3.php';

$filepath = '../../mp3/5231239/Gold_Jesus_Culture_Bryan_Katie_Tornwalt_.mp3';

$TaggingFormat = 'UTF-8';

$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TaggingFormat));

getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true);


$tagwriter = new getid3_writetags;
$tagwriter->filename       = $filepath;
$tagwriter->tagformats = array('id3v2.3');
$tagwriter->tag_encoding   = $TaggingFormat;

$tagwriter->tag_data = ["Track title"=>"Gold"];
        if ($tagwriter->WriteTags()) {
            echo 'Successfully wrote tags<BR>';
            if (!empty($tagwriter->warnings)) {
                echo 'There were some warnings: '.implode('<br><br>', $tagwriter->warnings);
            }
        } else {
            echo 'Failed to write tags! '.implode('<br><br>', $tagwriter->errors);
        }
        

ini_set("xdebug.var_display_max_children", -1);
ini_set("xdebug.var_display_max_data", -1);
ini_set("xdebug.var_display_max_depth", -1);

$info = $getID3->analyze($filepath);


var_dump($info);
0

There are 0 best solutions below