//
// available at http://getid3.sourceforge.net //
// or http://www.getid3.org //
// also https://github.com/JamesHeinrich/getID3 //
/////////////////////////////////////////////////////////////////
// //
// /demo/demo.write.php - part of getID3() //
// sample script for demonstrating writing ID3v1 and ID3v2 //
// tags for MP3, or Ogg comment tags for Ogg Vorbis //
// See readme.txt for more details //
// ///
/////////////////////////////////////////////////////////////////
die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']);
$TaggingFormat = 'UTF-8';
header('Content-Type: text/html; charset='.$TaggingFormat);
echo '';
echo '
getID3() - Sample tag writer';
require_once '../getid3/getid3.php';
// Initialize getID3 engine
$getID3 = new getID3;
$getID3->setOption(['encoding'=>$TaggingFormat]);
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true);
$browsescriptfilename = 'demo.browse.php';
$Filename = (isset($_REQUEST['Filename']) ? $_REQUEST['Filename'] : '');
if (isset($_POST['WriteTags'])) {
$TagFormatsToWrite = (isset($_POST['TagFormatsToWrite']) ? $_POST['TagFormatsToWrite'] : []);
if (! empty($TagFormatsToWrite)) {
echo 'starting to write tag(s)
';
$tagwriter = new getid3_writetags;
$tagwriter->filename = $Filename;
$tagwriter->tagformats = $TagFormatsToWrite;
$tagwriter->overwrite_tags = false;
$tagwriter->tag_encoding = $TaggingFormat;
if (! empty($_POST['remove_other_tags'])) {
$tagwriter->remove_other_tags = true;
}
$commonkeysarray = ['Title', 'Artist', 'Album', 'Year', 'Comment'];
foreach ($commonkeysarray as $key) {
if (! empty($_POST[$key])) {
$TagData[strtolower($key)][] = $_POST[$key];
}
}
if (! empty($_POST['Genre'])) {
$TagData['genre'][] = $_POST['Genre'];
}
if (! empty($_POST['GenreOther'])) {
$TagData['genre'][] = $_POST['GenreOther'];
}
if (! empty($_POST['Track'])) {
$TagData['track'][] = $_POST['Track'].(! empty($_POST['TracksTotal']) ? '/'.$_POST['TracksTotal'] : '');
}
if (! empty($_FILES['userfile']['tmp_name'])) {
if (in_array('id3v2.4', $tagwriter->tagformats) || in_array('id3v2.3', $tagwriter->tagformats) || in_array('id3v2.2', $tagwriter->tagformats)) {
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
ob_start();
if ($fd = fopen($_FILES['userfile']['tmp_name'], 'rb')) {
ob_end_clean();
$APICdata = fread($fd, filesize($_FILES['userfile']['tmp_name']));
fclose($fd);
list($APIC_width, $APIC_height, $APIC_imageTypeID) = getimagesize($_FILES['userfile']['tmp_name']);
$imagetypes = [1=>'gif', 2=>'jpeg', 3=>'png'];
if (isset($imagetypes[$APIC_imageTypeID])) {
$TagData['attached_picture'][0]['data'] = $APICdata;
$TagData['attached_picture'][0]['picturetypeid'] = $_POST['APICpictureType'];
$TagData['attached_picture'][0]['description'] = $_FILES['userfile']['name'];
$TagData['attached_picture'][0]['mime'] = 'image/'.$imagetypes[$APIC_imageTypeID];
} else {
echo 'invalid image format (only GIF, JPEG, PNG)
';
}
} else {
$errormessage = ob_get_contents();
ob_end_clean();
echo 'cannot open '.$_FILES['userfile']['tmp_name'].'
';
}
} else {
echo '!is_uploaded_file('.$_FILES['userfile']['tmp_name'].')
';
}
} else {
echo 'WARNING: Can only embed images for ID3v2
';
}
}
$tagwriter->tag_data = $TagData;
if ($tagwriter->WriteTags()) {
echo 'Successfully wrote tags
';
if (! empty($tagwriter->warnings)) {
echo 'There were some warnings:'.implode('
', $tagwriter->warnings).'
';
}
} else {
echo 'Failed to write tags!'.implode('
', $tagwriter->errors).'
';
}
} else {
echo 'WARNING: no tag formats selected for writing - nothing written';
}
echo '
';
}
echo 'Sample tag editor/writer
';
echo 'Browse current directory
';
if (! empty($Filename)) {
echo 'Start Over
';
echo '';
}
echo '';