Reputation:
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?
Upvotes: 0
Views: 846
Reputation: 845
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/
Upvotes: 1
Reputation: 30394
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.
Upvotes: 0
Reputation: 11141
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: https://www.php.net/manual/en/function.rename.php
G-Man
Upvotes: 0
Reputation: 5878
Is this what you're after? http://getid3.sourceforge.net/
Upvotes: 2
Reputation: 625107
You can use the getID3() parser to get MP3 file information.
There are also these ID3 PHP functions available.
Upvotes: 4