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! |
This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing. FREE! Go There Now!
|
|
|
|
This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
|
|
|
|
In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |