Location: PHPKode > projects > MP3 Intranet > mp3i-0.3.1/addnew.php
<? include_once("inc/header.php"); ?>
<?
include_once("inc/id3.class");

if($action)
{

	if(!$list)
	{
		if($erase)
		{
			$sql = "DELETE FROM songs";
			$result = @mysql_query($sql, $db);
		}
	}

	if(!$dir_name){ $dir_name = "/share/Music/singles"; }
	if(!$ftp_access){ $ftp_access = "http://www.google.com/"; }

	$dir = opendir($dir_name);
	while ($file_name = readdir($dir))
	{
	        if (($file_name != "." && $file_name != ".."))
	        {
			$complete_filename = $dir_name . "/" . $file_name;
			$get_sql = "SELECT server_file FROM songs WHERE server_file='$complete_filename'";
			$get_result = @mysql_query($get_sql, $db);
			$num_rows = mysql_num_rows($get_result);
			if($num_rows <= 0)
			{
				$file = $dir_name . "/" . $file_name;
				$id3 = new id3($file);

				// Cut up the filename.
	                	$new_file = explode("(", $file_name);
	                	$new_file = explode(")", $new_file[1]);
	                	$artist = $new_file[0];
	                	$new_file = explode("-", $new_file[1]);
	                	$new_file = explode(".", $new_file[1]);
	                	$song = $new_file[0];

				$length = $id3->length;
				$genre = $id3->genre;
				$artist_test = $id3->artist;
				$song_test = $id3->name;
				if($artist_test){ $artist = $artist_test; }
				if($song_test){ $song = $song_test; }

				if($write)
				{
					$id3->artists = $artist;
					$id3->name = $song;
					$id3->comment = "-=|| Added By MP3i http://mp3i.sourceforge.net ||=-";
					$id3->write();
				}

	                	print "$file_name ($num_rows)<br>";
	                	print "Artist: $artist<br>\n";
	                	print "Song Title: $song<br>\n";
	                	print "Length: $length<br>\n";
	                	print "Genre: $genre<br>\n";
				print "<hr align=\"left\" width=\"25%\">";

				if(!$list)
				{
					$sql = "INSERT INTO songs (filename, artist, song, length, genre, server_file) VALUES ('$ftp_access/$file_name', '$artist', '$song', '$length', '$genre', '$file')";
	                		$result = @mysql_query($sql, $db);
				}
	        	}
			else
			{
				print "Already Have $file_name<br>";
			}
		}
	}
	closedir($dir);
}
else
{
	print "<form action=\"$PHP_SELF\">\n";
	print "<table width=\"25%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
	print " <tr>\n";
	print "  <td nowrap bgcolor=\"#c0c0c0\" class=\"header\" align=\"center\" colspan=\"2\">Add New MP3s</td>\n";
	print " </tr>\n";

	print " <tr>\n";
	print "  <td colspan=\"2\" nowrap class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"list\">&nbsp;&nbsp;Just list files (DO NOT ADD)&nbsp;</td>\n";
	print " </tr>\n";

	print " <tr>\n";
	print "  <td colspan=\"2\" nowrap class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"erase\">&nbsp;&nbsp;Clear Database (If using the same directory)&nbsp;</td>\n";
	print " </tr>\n";

	print " <tr>\n";
	print "  <td nowrap class=\"main\" align=\"right\"><input type=\"text\" name=\"dir_name\" size=\"30\">&nbsp;&nbsp;</td>\n";
	print "  <td nowrap class=\"main\" align=\"left\">MP3 Directory</td>\n";
	print " </tr>\n";

	print " <tr>\n";
	print "  <td nowrap class=\"main\" align=\"right\"><input type=\"text\" name=\"ftp_access\" size=\"30\" value=\"http://www.yourdomain.com/mp3s\">&nbsp;&nbsp;</td>\n";
	print "  <td nowrap class=\"main\" align=\"left\">FTP Access to mp3s (If Available for download)</td>\n";
	print " </tr>\n";

	print " <tr>\n";
	print "  <td colspan=\"2\" nowrap class=\"main\" align=\"center\">&nbsp;</td>\n";
	print " </tr>\n";

	print " <tr>\n";
	print "  <td colspan=\"2\" nowrap class=\"main\" align=\"center\"><input type=\"submit\" name=\"action\" value=\"Add MP3s\"></td>\n";
	print " </tr>\n";

	print "</table>\n";
	print "</form>\n";

	print "</table>\n";
}
?>
<? include_once("inc/footer.php"); ?>
Return current item: MP3 Intranet