This is for use on a home computer with many MP3s stored on it. It will print out a list of the MP3s in a given directory (to change the directory, change the definition of $default_dir). The page will display a list of the files with each name acting as a link to the file so that it can be played. Of course, some individual modifications must be added to prevent it from echoing out files such as resume.dat or incomplete files, but these need to be added by the user for his/her individual setup. Also added are the shuffle, alphabetical, and reverse alphabetical sorters as well as the option to list incomplete files and the ability to search the files. It is also possible to navigate the directory heirarchy and folders are conveniently listed in bold. PHP must be installed for this code to work. Check back often as I am continuing to update the code and add new features. - Kate, webmaster@griflet.com
By : kate2587
<html><head>
<title>Music Library</title>
<style type="text/css">
a {text-decoration: none; color: navy;}
a:hover {text-decoration: underline; color: black;}
body, a {font-family: 'Trebuchet MS'; font-size: 10pt;}
</style>
</head>
<body>
<center>
<h1>Music</h1>
<br>
</center>
<table border="0" width="100%">
<tr><td width="75%" valign="top">
<center>
<b><span style="color: black; size: 12;">song list</span></b><br><br>
</center>
<?php
$default_dir = "C:\\program files\\napster\\music";
if (!(isset($searchFor)) && !(isset($sort_order))) {$display = "all";}
$allEnds = "sort_order=$sort_order&include=$include&searchFor=$searchFor&search=$search&display=$display&dir=$dir";
if (empty($dir)) {$dir = $default_dir;}
$dp = opendir($dir);
if (empty($searchFor)) {$display = "all";}
if (ereg("\\\\",$dir))
{
$dir2 = str_replace("\\\\","\\",$dir);
if (isset($dir2))
{
$dir = $dir2;
}
}
while($file = readdir($dp)) $filenames[] = $file;
if (($sort_order == "alphabetical") || !(isset($sort_order)))
{ sort($filenames);
$sort_order = "alphabetical"; }
else if ($sort_order == "shuffle")
{ shuffle($filenames); }
else if ($sort_order == "reverse_alphabetical")
{ rsort($filenames); }
for($i = 0; $i < count($filenames); $i++)
{
$file = $filenames[$i];
if (
(($include == "0") && ((eregi("incomplete", $file)))) ||
($file == ".") ||
!(($display == "all") || (($search == "1") && ($searchFor != "") && (eregi("$searchFor", $file))))
)
{}
else
{
if ((eregi(".+\.[A-Z0-9]{3,4}",$file)) || (eregi(".+\.com",$file)))
{
if (ereg(".mp3",$file)) {$parts = explode(".mp3", $file);} else if (ereg(".MP3", $file)) {$parts = explode(".MP3", $file);} else if (ereg(".mP3", $file)) {$parts = explode(".mP3", $file);} else {$parts = explode(".Mp3", $file);}
echo "<a href=\"$dir\\$file\"";
if (!(eregi(".mp3",$file))) {echo " target=\"_blank\"";}
echo ">$parts[0]</a><br>\n";
}
else
{
if ($file == "..")
{
echo "<a href=\"$PHP_SELF?dir=$dir\\..\"><b><i>Above Directory</i></b></a><br>\n";
}
else
{
echo "<a href=\"$PHP_SELF?dir=$dir\\$file\"><b>$file</b></a><br>\n";
}
}
}
}
?>
</td>
<td width="25%" valign="top">
<center>
<b><span style="color: black; size: 12;">sort order</span></b><br><br>
<a href="<?php echo "$PHP_SELF?$allEnds&sort_order=alphabetical";?>">alphabetical</a><br><br>
<a href="<?php echo "$PHP_SELF?$allEnds&sort_order=reverse_alphabetical";?>">reverse alphabetical</a><br><br>
<a href="<?php echo "$PHP_SELF?$allEnds&sort_order=shuffle";?>">shuffle</a><br><br>
<?php
if ($include == "1")
{ $newinclude = "0"; }
else
{ $newinclude = "1"; }
echo "<br><br><form>";
echo "<a href=\"";
echo "$PHP_SELF?$allEnds&include=$newinclude";
echo "\"><input type=\"checkbox\"";
if ($newinclude == "0")
{echo " checked";}
echo "> Include incomplete files (these files may not be playable)</a>
</form>";
?>
<br><br>
<form action="<?php echo $PHP_SELF; ?>" method="get">
<input type="text" name="searchFor" value="<?php if (isset($searchFor)) {echo $searchFor;}?>">
<input type="hidden" name="include" value="<?php echo $include; ?>">
<input type="hidden" name="sort_order" value="<?php echo $sort_order; ?>">
<input type="hidden" name="dir" value="<?php echo $dir; ?>">
<input type="hidden" name="search" value="1">
<input type="submit" value="search" style="border-width: 1; border-color: black; font-color: black; background: white; font-family: 'trebuchet ms';">
</form>
<a href="<?php echo "$PHP_SELF?sort_order=$sort_order&include=$include&display=all&dir=$dir";?>">display all</a>
<br><br>
<a href="<?php echo "$PHP_SELF?sort_order=alphabetical&include=0"; ?>">Default Directory</a>
</center>
</body>
</html>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
|
|
|
|
Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs). FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
|
|
|
|
You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |