Important alert: (current site time 7/15/2013 11:26:07 AM EDT)
 

VB icon

MP3 Archiver

Email
Submitted on: 1/9/2001 6:19:24 PM
By: Steve Oliver 
Level: Intermediate
User Rating: By 7 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 26680
(About the author)
 
     This script will grab all the mp3's in a folder, get the Tags from them, ie.Title, Author, Album, Copyright, Comments, and will list them all on a page, in tables. Also it shows how to upload mp3's using a browser, and add them to that folder, which will then automatically add it to your list.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: MP3 Archiver
// Description:This script will grab all the mp3's in a folder, get the Tags from them, ie.Title, Author, Album, Copyright, Comments, and will list them all on a page, in tables. Also it shows how to upload mp3's using a browser, and add them to that folder, which will then automatically add it to your list.
// By: Steve Oliver
//
// Inputs:You must input 3 variables.
$destination
$directory
$url
//
// Side Effects:No side effects found as of yet.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=249&lngWId=8//for details.//**************************************

<?PHP
function SubmitSong($filename,$filename_name){
#Desination path that mp3s will be uploaded to.
$destination="/path/to/mp3/folder/";
if (ereg(".mp3",$filename_name)){
copy($filename,$destination.$filename_name);
echo "<h1>File Uploaded...</h1>";
echo "<b>$filename_name was uploaded succesfully.</b><br><br>";
echo "<a href=\"mp3.php\">Click here to go back.</a>";
}else{die("<h1>Not a Valid mp3 file...</h1>"); }
}
function main(){
###################################################################
#URL to directory containing your mp3s
$url="http://www.yoursite.com/mp3s/";
#actual location of your mp3 folder
$directory="path/to/mp3/folder/";
###################################################################
$count=0;
$handle=opendir($directory);
while (($filename = readdir($handle))!==false) { 
if ($filename != "." && $filename != ".." && ereg(".mp3",$filename)) {
$count++;
echo "<b>Song Number: $count</b>";
getTag($filename,$directory,$url);}
}
closedir($handle); 
####################################################################
#This part adds a submit form to allow people to upload mp3s to you.
#If they are on a slow connection the script will time out unless
#you change the timeout rate of your script.
?>
<form method="post" action="mp3.php" enctype="multipart/form-data">
Submit MP3: 
<input type="file" name="filename" size="20" tabindex="5">
<input type="hidden" name="action" value="SubmitSong">
<input type="submit" value="Submit" tabindex="8">
</form><?
}
####################################################################
function getTag($filename,$directory,$url){
$filetitle=$filename;
$filename= $directory.$filename;
$fp=fopen($filename,"r");
fseek($fp,filesize($filename)-128);
$checktag=fread($fp,3);
echo "<table width='100%' border='1' bgcolor='#c0c0c0'><tr><td>";
echo "<b><a href=\"$url$filetitle\">$filetitle</a></b><br></tr></td><tr><tr><tr bgcolor='#FFFFFF'><td>";
if ($checktag=="TAG") {
echo "Size: ".number_format(filesize($filename)/1000,2)." KBytes<br>";
echo "Title: ".fread($fp,30)."<br>";
echo "Author: ".fread($fp,30)."<br>";
echo "Album: ".fread($fp,30)."<br>";
echo "Copyright: ".fread($fp,4)."<br>";
echo "Comments: ".fread($fp,30)."<br>";
echo "</td></tr></table><br>";
}else{
echo "Size: ".filesize($filename)." Bytes<br>";
echo "<font color=\"red\"><b>No Tag</b></font><br>";
echo "</td></tr></table><br>";
fclose($filename);}
}
switch ($action){
	default:
	main();
	break;
	case "SubmitSong":
	if ($filename=="none") {echo("<h1>No File Selected....</h1>"); break;}
	submitsong($filename,$filename_name);
	break;
}
?>


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/9/2001 6:43:19 PMSteve

I'm just learning php, been at it for about 2 weeks now, I would love to hear any comments or suggestsion on this.
(If this comment was disrespectful, please report it.)

 
2/17/2001 11:21:33 PM:: em ::

I think it s u c k s...that I don't code in php, yet :) you got my vote n you know why (wink)
(If this comment was disrespectful, please report it.)

 
3/11/2001 3:59:39 AMalex

Great code :]
I never knew PHP was so good.
(If this comment was disrespectful, please report it.)

 
3/15/2011 12:12:06 AMwanchai126

anyone know how to build mp3 player online with php coding script..please
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.