Miscellaneous Code

  Home arrow Miscellaneous Code arrow Music Library
MISCELLANEOUS CODE

Music Library
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-10-08

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    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

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap