PHP Code

Posted on 2011-10-21
Medium Priority
Last Modified: 2012-06-27
Can any one help me. I need a simple PHP code that will read the content of an online folder on my wbt site for example http://theonlinebeatz.com/Music/Bachata. I will like to know the name of the file ext (I wish only to read MP3) I would like to keep a list of the files that are currently in the folder
Question by:Zirwo01
  • 2
  • 2

Accepted Solution

Hellmark earned 2000 total points
ID: 37009387
This is based on code found from http://php.net/manual/en/function.opendir.php

  //$current_dir = "$DOCUMENT_ROOT"."/";    //Put in second part, the directory - without a leading slash but with a trailin$
  $current_dir = "./";
  $dir = opendir($current_dir);        // Open the sucker
  echo ("<p><h1>List of available files:</h1></p><hr><br />");
  while ($file = readdir($dir))            // while loop
    $parts = explode(".", $file);                    // pull apart the name and dissect by period
    if (is_array($parts) && count($parts) > 1) {    // does the dissected array have more than one part
        $extension = end($parts);        // set to we can see last file extension
        if ($extension == "mp3" OR $extension == "MP3")    // is extension ext or EXT ?
             echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />";    // If so, echo it out else do nothing cos it's$
  echo "<hr><br />";  

  closedir($dir);        // Close the directory after we are done

Open in new window


Author Comment

ID: 37010174
This is awsome what about if I would like it in aphabeticle order?

Expert Comment

ID: 37010997
I guess what you need is some .htaccess
for example the url you provided could be

and if you can make your system like this e.g.: file.php?name=xxxxxxxx

then with some htaccess tricks you can change the way url is shownn


Author Comment

ID: 37011288
I am not following you gnito....is this for the read folder content?

Expert Comment

ID: 37012996
It appears as if they misread the question, in that thinking you have a php script, and you want it to appear as if it is a directory. Which, there are simpler ways than using .htaccess to do that as well ('d have just made a folder named /music/ and named the script index.php and placed it in the folder).

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question