[英]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.