开发者

Open web directory to simple webpage

开发者 https://www.devze.com 2022-12-21 10:42 出处:网络
This is a fairly simple problem, I\'m just not sure exactly how to approach it. A friend of mine has an open directory on his webserver, and he asked me to make a simple webpage for him which would j

This is a fairly simple problem, I'm just not sure exactly how to approach it.

A friend of mine has an open directory on his webserver, and he asked me to make a simple webpage for him which would just display all of the file names, rather than the dates/file sizes/etc. The page would also update when a new file is added into the directory.

So, I guess I'm just looking to be pointed in the right direction on this one. My first guess was just to throw a simple HTML/Javascript page together which would extract all of the 开发者_StackOverflow社区file names from the directory with Javascript, then display them on the webpage while linking to the file. Or am I going able this all wrong?

Thanks,

aqzman


JavaScript is a client-side language and really has no way of enumerating files and directories on a web server, without the aid of a server-side script anyway. You need to look into server-side scripting languages such as Python, PHP, and ASP.NET (Windows Server only), to name a few.

These languages are processed on the server and make changes to (or even create from scratch) a page before it is sent to the client/browser.


You could use Apache's built-in directory listing feature. With javascript this can't really be done (exception: there's a pattern within the filenames that would let you send HEAD requests to see if files exist - see this site where I had to use this technique).


You can do this pretty easily with PHP -

$files = scandir($_GET['dir']);
foreach ($files as $file) {
    if (is_dir($_GET['dir']))
        echo '<a href="?dir='.$_GET['dir'].'/'.$file.'">'.$file.'</a><br />';
    else
        echo '<a href="'$_GET['dir'].'/'.$file.'">'.$file.'</a><br />';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号