Mohammad
Mohammad

Reputation: 179

How change mp3 tag and photos with PHP?

How change MP3 photo with php ?

I use id3_get

But in demos not found change photo

Upvotes: 1

Views: 3404

Answers (2)

Ollobergan Karimov
Ollobergan Karimov

Reputation: 41

In my case I use composer.

composer require james-heinrich/getid3

index.php file

<?php
require __DIR__.'/vendor/autoload.php';

$getID3 = new getID3;

$tagwriter                      = new getid3_writetags;
$tagwriter->filename            = './music.mp3';
$tagwriter->tagformats          = array('id3v1','id3v2.3');
$tagwriter->overwrite_tags      = true;
$tagwriter->remove_other_tags   = true;
$tagwriter->tag_encoding        = 'UTF-8';
$pictureFile = file_get_contents("logo.png");

$TagData = array(
    'title'             => array('My Title'),
    'artist'            => array('My Artist'),
    'attached_picture'  => array(
        array (
            'data'          => $pictureFile,
            'picturetypeid' => 3,
            'mime'          => 'image/png',
            'description'   => 'My Picture'
        )
    )
);

$tagwriter->tag_data = $TagData;

if ($tagwriter->WriteTags()){
    return true;
}else{
    throw new \Exception(implode(' : ', $tagwriter->errors));
}
?>

Upvotes: 2

Related Questions