开发者

html showing contents of folder

i am creating a web page to show the contents of a folder so that people can view the files and download them if needed.

<a href="file:///C:\inetpub\wwwroot\test_pages">Click here to view Folder</a>

But i wanna do this without any codin开发者_如何学运维g what so ever, i found this code which lets me view files. The problem i am facing is that when i double click the html page and open it this hyperlink works and i get what i need but when i access the page through a server (IIS 7) then the hyperlink does nothing ? am i to set some permissions or what ? can someone tell me what im doing wrong ?


The link will work when the file you want to download is on your own personal computer, which in your case is true if you're just showing the HTML file locally. It won't be true for users visiting your website from another computer though.

If you want to serve the file on a server, you need to link to the path on the server itself, that is, if the file is in C:\inetpub\wwwroot\test_pages, your A HREF looks like this:

<a href="/test_pages">Click here to view Folder</a>

Offcourse, this will work for simple files. For folders, you need to enable the webserver to show directory contents by enabling Directory Browsing.


There are security implications of linking to a local file from an online source. It works when the page is held locally but when on a server it puts a stop to it.


You can also use linux build-in command Tree, in example below you can see that i only want to add files that are matching .tar.gz or .zip or .tar.bz2

tree -P "*.tar.gz|*.zip|*.tar.bz2" -h -D --dirsfirst -r -H . > index.html;

You can also add a custom css to the page for a better looking output.

Straighforward and highly secure since the result is only html

as you use windows you can use www.cygwin.com to emulate a linux environement

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜