Read and Write ID3 Tags Using PHP

I want to write my own php script to read and write ID3v2 tags for MP3 files without using PHP’s id3_set_tag() function since my compilation of PHP does not support id3. I do not want to try to recompile php - it is outside my area expertise and I do not want to go through it again every time my host updates php versions.

I do not want a separate program that does ID3 editing - it needs to be a part of the php program I am writing that allows users to upload audio files to the site.

Anyone know the simplest way to read and write the tags? I get lost in classes and OOP because they not intuitive to me, but if you can share some code with me I would appreciate it!

You need to do file based operations. You need to read the headers that has the ID3 information stored.

Does anyone have a code example to extract a single ID3v2 tag such as Title from an MP3 file? If I could see one example, I could expand to get other tags as well. Thank you.

You don’t want to use the built-in library?

I would love to use id3_set_tag(), but it requires this, which I know too little about to try:

id3 is part of PECL and can be installed using the PEAR installer. To compile
PHP with id3 support, download the sourcecode, put it in php-src/ext/id3 and
compile PHP using --enable-id3.

First hit on google

It doesn’t look like there is a PEAR requirement.

Sorry, but I don’t know what to do with this: http://getid3.sourceforge.net/

I have spent hours Googling, reading, and trying to figure out what to do.

I was wanting to write php code that goes into an application I am making for users to upload audio files. The code is to allow the users to edit id3v2 data of the files they are uploading and is to be a function in my existing application.

Right now I have redundancy - the title, location, date, etc. are stored separately in a database, which is redundant to the id3 data. I was wanting to eliminate the redundancy, but I suppose I should wait until a php release is made in the future in which id3 functions are enabled.

Both the php coding option and the php recompilation option look too complicated for me at this time, which is why I turned to this forum hoping someone could provide a very simple php code example that I could learn from and expand upon. Thanks anyway.

That’s the download page. Looks like there’s a decent readme and good code examples for making use of it.

Looks like getid3 only reads. It doesn’t write.

What is your issue? Are you developing on Windows? Hosting your own web server? If you have a web host, you can ask them to install the PECL ID3 package. For your development box, if you don’t have a Windows compiler, you could switch to using a Linux box.

I used DreamHost shared hosting. I develop with a Mac. The web host will not support recompiling php for me:

"I can’t assist you with the development of your website including software
configured to run said website. This is something that has to be done by
you or someone else --DH techs can’t do this for you!

Basically, you’ll need to install a custom version of PHP and then
install the proper extensions along with it. We do have a wiki article to
assist you with this, you can find that here:
http://wiki.dreamhost.com/Installing_PHP5

If you don’t know how to do this then I suggest that you hire a web
developer to assist you."

What OS is your hosting on? It might be Linux.

Install Parallels on your Mac. Install gcc. Run Linux in Parallels. Install Apache and MySQL (or other database) in Linux. Download PHP source. Follow directions, enable ID3 package. Away you go.

Test your install for Dreamhost by uploading your newly generated binaries to Dreamhost, and get it running there.

While all this is not simple, I believe it would be much easier than writing your own ID3 editor from scratch–in any language.

With your special requirements, you will want to shift to running it on your own web server sooner rather than later.

Good luck.

Kronso, that tends to make sense! Thank you!