PHP Code

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 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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HellmarkLinux Systems AdministratorCommented:
This is based on code found from

  //$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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Zirwo01Author Commented:
This is awsome what about if I would like it in aphabeticle order?
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
Zirwo01Author Commented:
I am not following you this for the read folder content?
HellmarkLinux Systems AdministratorCommented:
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).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.