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
14die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
15
16
17$TextEncoding = 'UTF-8';
18
19require_once('../getid3/getid3.php');
20// Initialize getID3 engine
21$getID3 = new getID3;
22$getID3->setOption(array('encoding'=>$TextEncoding));
23
24require_once('../getid3/write.php');
25// Initialize getID3 tag-writing module
26$tagwriter = new getid3_writetags;
27//$tagwriter->filename = '/path/to/file.mp3';
28$tagwriter->filename = 'c:/file.mp3';
29
30//$tagwriter->tagformats = array('id3v1', 'id3v2.3');
31$tagwriter->tagformats = array('id3v2.3');
32
33// set various options (optional)
34$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)
35$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.
36$tagwriter->tag_encoding      = $TextEncoding;
37$tagwriter->remove_other_tags = true;
38
39// populate data array
40$TagData = array(
41	'title'                  => array('My Song'),
42	'artist'                 => array('The Artist'),
43	'album'                  => array('Greatest Hits'),
44	'year'                   => array('2004'),
45	'genre'                  => array('Rock'),
46	'comment'                => array('excellent!'),
47	'track_number'           => array('04/16'),
48	'popularimeter'          => array('email'=>'user@example.net', 'rating'=>128, 'data'=>0),
49	'unique_file_identifier' => array('ownerid'=>'user@example.net', 'data'=>md5(time())),
50);
51$tagwriter->tag_data = $TagData;
52
53// write tags
54if ($tagwriter->WriteTags()) {
55	echo 'Successfully wrote tags<br>';
56	if (!empty($tagwriter->warnings)) {
57		echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
58	}
59} else {
60	echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
61}
62