View Full Version : Directory Compilation.
boxxertrumps
08-27-2006, 09:36 PM
is there any existing program that scans a directory (presumabally the one your webpage is in) and creates a html file with links to every file in that directory?
eg:
Directory
___\_->sub folder
_________\_->1.mp3
_____________2.mp3
_____________3.mp3
______sub folder
_________\_->a.mp3
_____________b.mp3
_____________c.mp3
______sub folder
_________\_->x.mp3
_____________y.mp3
_____________z.mp3
Html file
link to 1.mp3
" "2.mp3
" "3.mp3
" "a.mp3
" "b.mp3
" "c.mp3
" "x.mp3
" "y.mp3
" "z.mp3
Thankyou for your time.
Not in HTML, you can't. But in a server-side language it's easy; in PHP, for example, it would be:
<?php
$cwd = $_SERVER['REQUEST_URI'];
$cwd = substr($cwd, 0, strrpos($cwd, '/' + 1));
function paintUndersideOfFox($c) {
global $cwd;
echo('<ul class="dirlist">');
$d = opendir($c);
while($f = readdir($d)) {
if(strpos($f, '.') === 0) continue;
$ff = $c . '/' . $f;
echo('<li><a href="' . $cwd . $ff . '">' . $ff . '</a></li>');
if(is_dir($ff)) paintUndersideOfFox($ff);
}
echo('</ul>');
}
paintUndersideOfFox('.');
?>
boxxertrumps
08-28-2006, 02:17 AM
Thankyou. now i just have to install php...
mwinter
08-28-2006, 10:58 AM
Your server may be able to generate a directory listing automatically. With Apache, for example, the mod_autoindex module is responsible for generating listings when an index (like index.html or default.html; whatever the server is configured to use) isn't present.
You might want to ask your host if the module (or a similar feature on other servers) is enabled, or if they will provide it for you before delving too far into server-side scripting.
Mike
boxxertrumps
08-28-2006, 04:16 PM
I am my own host... and talking to myself isnt exactly o good thing to do.... i have Abyss installed on my computer and it works fine. on their website it gives a step by step procedure of how to enable it. and the Code works great Pr. Twey, your a genuis.
talking to myself isnt exactly o good thing to do...Really? :-\ Damn...
and the Code works great Pr. Twey, your a genuis.Genius or cracked as grandma's gravy boat, one or the other :)
ItsMeOnly
08-29-2006, 09:37 AM
just a quick addition: there's a potential security hole if anyone would use "globbing" (i.e. ../../../../), normally the server would ignore the overstepping up dirs, however php will not unless you chroot the script onto document root or strip "../" from the $cwd
Or... just check user input before using the function with it, like you should be doing anyway :) The OP didn't mention user input, so I naturally assumed that s/he wouldn't be using it -- or that s/he is smart enough to know that all user input must be validated before use anyway.
"globbing" (i.e. ../../../../)That's not globbing. :) .. exists as an actual directory on the filesystem.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.