简体   繁体   English

写入标签后如何保存文件?

[英]How do I save the files after the tags have been written?

I'm trying to change the track details of an mp3 file with the getID3 library, which I then want to save to a directory. 我正在尝试使用getID3库更改mp3文件的曲目详细信息,然后将其保存到目录中。

How do I save the files after the tags have been written? 写入标签后如何保存文件?

<?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);
}

The file has the tags written to after the method has been called. 该文件具有在调用方法后写入的标签。

$localtempfilename = tempnam('/tmp', 'getID3');

Here is where you place the file on your machine, this is also where the file is "saved". 在这里将文件放置在计算机上,这也是“保存”文件的地方。 When you've done everything you've wanted then the changes will be saved to this file. 完成所需的所有操作后,更改将保存到该文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM