views:

187

answers:

6

Hi,

I have just made a file upload form, and so far I have it so that users can only upload their own .mp3's;

Currently, all my form does is change the filename to $username . " - " . $title; in which the variables they enter;

The form is still in beta, however, and I am asking if there is a way I can view the file information (for .mp3 if not all files) with PHP, and then rewrite the file information with the $username and $title, and additional inputs from the user - that is, before uploading the file.

How can I do so?

+4  A: 

You can use the getID3() parser to get MP3 file information.

There are also these ID3 PHP functions available.

cletus
+2  A: 

Is this what you're after? http://getid3.sourceforge.net/

Andrei Serdeliuc
A: 

It sounds like you're just trying to rename the file. If that's the case you'd do something like this:

copy($OrigPath . $OrigFilename, $OrigPath . $Username . " - " . $Title . $OrigFilename);

Reference: http://us2.php.net/manual/en/function.rename.php

G-Man

GeoffreyF67
A: 

If you're really asking if you can get file information "before uploading the file," then No, you can't. You can't read files on a client's hard drive from a web server. Other answers cover what you can do after the file is uploaded.

Scott Saunders
+1  A: 

The are various ways of doing this....there is a pecl ext called id3 which allows you to read and set tags to the mp3 file.

link to pecl:http://pecl.php.net/package/id3 , also here is a link to a nice tutorial on how to use the ext....http://devzone.zend.com/article/4025-Reading-and-Writing-MP3-and-Photo-Metadata-with-PECL-

Should the mp3 tags not be set on the file, you can always try ffmpeg which will give all the information about the file encoding ...there is also a php lib that wraps around ffmpeg which might be useful http://sourceforge.net/projects/ffmpeg-phpclass/

Ronald Conco
+1  A: 

If you can't install the php id3 module you can use this function.

Pons