Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I am having a problem. I can find snippets of code on the web but nothing designed to do what I want.
I have a directory which I share on my IIS server, it is just a link to a directory with directory browsing enabled.
I would like to customise this page with a background / showing just mp3's and make all the mp3's clickable etc etc and I don't know how to program this using PHP (I'm very new to it)
I have tried opendir() but I think this is just for internal calls.
Any help would be much appreciated,
Thanks a lot
Shaun

Below is a script that I wrote in PHP to give me a directory readout of all my dirs and files and hyperlinks them for access in a web browser. Perhaps you will find it useful for what you are trying to do.
--------
<?php
$imgDir = opendir("YOUR-MP3-DIRECTORY");
while($imgName = readdir($imgDir))
{
if (($imgName != ".") || ($imgName != ".."))
print("$imgName
\n");
}
?>
--------I have a few questions for you now ;)
1) Why choose IIS over Apache?
2) Have any good music??At any rate, this script should get you what you want, adding a background image to the site is fairly trivial. Post back here if you have problems.
IR

Thought I could just throw code out and have it work in the forum, I guess I need to use the coder facility next time as I lost some code. The print line should read as follows:
print("[LT]A HREF=\"$imgName\"[GT]$imgName[LT]/A[GT][LT]BR[GT]\n");
The [LT] is a less than symbol.
The [GT] is a greater than symbol.IR

Hi,
Fantastic - That's nearly done the trick thanks,
I have a couple more questions:
1) How can I exclusively specify what file extentions to show
2) How can I tell it to show just folders and/or files in a specific folder
3) Would I need to place this in each folder or can I use it to browse through folders/subfolders and back again.
In answer to your questions :
1) Simply because we run IIS at my place of work and I would do far better to learn how IIS works for my job. I'm sure apache is better - I have never used it before.
2) Please feel free to take a look:
http://80.6.32.33:8080
Username: computing
Password: helpI am using your program here http://80.6.32.33:8080/music/song lists/athlete/listing.php
and here
http://80.6.32.33:8080/music/song lists/listing.php
You see - I have many folders and files and I would like to be able to use your code after a successful login to browse through the folders and files and back again...without pasting the listing.php in every folder.
Thanks for your help, much appreciated,
Shaun

1) To only show certain exensions, change the if statement to:
if ((($imgName != ".") || ($imgName != "..")) && (strcmp(substr($imgName, -4), ".mp3")))to only show '.mp3's. Just change the .mp3 to something else for other extensions, but if the extension is 4 characters instead of three, you have to change the -4 to a -5. I think that should work.
2) This is a little trickier. The only way I can think of is to exec() the command `ls -l`, and look for directory entries. I'll provide more details if others think this is a good idea (IR?)
3) Not necessarily. You could have a variable that gets passed to the script when you click on a directory. Like if you changed the first $imgName in IR's print statement in his second post to $_SERVER['PHP_SELF'] . "?dir=$imgName" or something. But I'm not sure if $_SERVER is used in IIS, as I usually use Apache. But this might be getting a little advanced, so put it in every directory if you want.
And by the way, the reason that the '.'s and '..'s are showing up is that IR violated one of the most important rules with strings (haha), in that he used != to compare them! bah. So actually that if statement should be:
if ((strcmp($imgName, ".") != 0) || (strcmp($imgName, ".." != 0)))
unless I'm missing something. Remember, I'm not familiar with IIS, so I'm just speculating. Have fun!
-zeroguy

1) Zeroguy answered that question for you... just be careful to accomodate the file extensions accordingly.
2) You can have a comparison for each element of the array using the IsAFile and/or IsADirectory function. I came across these functions before, they are fairly
obscure, maybe they are in a wrapper class. But they will work when you find them...3) Place the directory script I wrote for you in your main directory, I suppose on IIS that would be your Inetpub by default, on Apache it is the htdocs. This way, you can browse every directory that has read / listing privilege. Just put my script where ever you want your "root" to be.
---
1) Smart man, that's the reason I wanted to run Apache.
2) Looks good. Glad the my script came in handy for you, I knew it would, it was handy for me ;). I haven't had a chance to review your music yet... but noticed some of my old favorites. I'll have to check it out, when this damn program stops executing, its been running since 730am, its now 9:21pm.
Again, you don't need the listing.php in every folder, just place it in your main public HTML directory (inetpub for IIS, htdocs for Apache) and it will scan and include every directory you have that has listing priveleges... it automatically filters the ones that are locked down.
----
Zeroguy:
You are right about the . and .. showing up and the reasons that they do... However, perhaps in my instance of this script, I overloaded the != operator or have redefined the string class. Both possible... But, no... I didn't do that. Honest, mistake...
wasn't able to test it off hand. This script was originally part of a larger project where the directory level options were needed, I suppose that's why I never caught it... just wasn't a problem.Glad it worked out, looks good :)
IR

You might just have the link go back to the main listing.php but with a variable of the group directory name. THen you would only need one of the files.

Thanks for all your help,
The if statement to remove all files that are not mp3's works in reverse. It allows all files that are not mp3!! :) How do I change the statement to allow all mp3's??
ORIGINAL IF STATEMENT:
if ((($imgName != ".") || ($imgName != "..")) && (strcmp(substr($imgName, -4), ".mp3")))
Thanks
Shaun

I am sure someone has a better way...
All I did was make the addition of the not operator (!). Try this out and see if it works...if ((($imgName != ".") || ($imgName != "..")) && (!(strcmp(substr($imgName, -4), ".mp3"))))
IR

Terribly sorry, i meant strcmp(substr($imgName, -4), ".mp3") == 0 , I just forgot the == 0 at the end, but IR's solution should work just as well.

Hi,
Thank you all for your help!
I don't know any PHP and so your help has been invaluable. My directory listing's look so much better.
If you want to download any songs, please do:
http://80.6.32.33:8080
Username: computing
Password: helpThanks again,
Shaun

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |