![](/img/trans.png)
[英]How do I safely include php files that may have whitespace after closing php tags?
[英]How do I save the files after the tags have been written?
我正在嘗試使用getID3庫更改mp3文件的曲目詳細信息,然后將其保存到目錄中。
寫入標簽后如何保存文件?
<?php
$remotefilename = 'http://musicbaap.com/public/music/Same-Beef-[Original]-Sidhu-Moose-Wala.mp3';
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 8192)) {
fwrite($fp_local, $buffer);
}
fclose($fp_local);
$getID3 = new \getID3;
$tagwriter = new \getid3_writetags;
$tagwriter->filename = $localtempfilename;
$tagwriter->tagformats = array('id3v1', 'id3v2.3');
// set various options (optional)
$tagwriter->overwrite_tags = true;
$getID3->encoding = 'UTF-8';
$tagwriter->tag_encoding = 'UTF-8';
$tagwriter->remove_other_tags = true;
// populate data array
$TagData['title'][] = 'My Song';
$TagData['artist'][] = 'The Artist';
$TagData['album'][] = 'Greatest Hits';
$TagData['year'][] = '2004';
$tagwriter->tag_data = $TagData;
// write tags
if ($tagwriter->WriteTags()) {
echo 'Successfully wrote tags<br>';
if (!empty($tagwriter->warnings)) {
echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
}
} else {
echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
}
// dd($tagwriter);
}
fclose($fp_remote);
}
該文件具有在調用方法后寫入的標簽。
$localtempfilename = tempnam('/tmp', 'getID3');
在這里將文件放置在計算機上,這也是“保存”文件的地方。 完成所需的所有操作后,更改將保存到該文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.