列出网页中目录的文件 [英] Listing files of a directory in a webpage

查看:147
本文介绍了列出网页中目录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以用链接查看网页中的目录文件。



我想上传一些PDF文件到某些目录我的静态网站(HTML + JS),并希望显示在一个页面中的文件列表中的链接,查看PDF文件,以便如果我上传新文件,我不必每次修改HTML页面,有没有办法做到这一点?

解决方案

如果您使用Apache作为Web服务器并配置 mod-autoindex 为你上传pdf文件的目录,那么你应该probalby看到somethink像此时导航到该网址:




这个自动生成的页面可以通过js使用jquery轻松解析:

  var pdfFilesDirectory ='/ uploads / pdf /'; 
$ b $ //获取自动生成的页面
$ .ajax({url:pdfFilesDirectory})。then(function(html){
//创建临时DOM元素
var document = $(html);

//找到以.pdf结尾的所有链接
document.find('a [href $ =。pdf]')。each(function ){
var pdfName = $(this).text();
var pdfUrl = $(this).attr('href');

//做什么想在这里
})
});


Is there any way to list the files of a directory in a webpage with the link to view the file.

I would like to upload some PDF files to certain directory of my static website (html + js), and want to show the list of the files in a page with the link to view the pdf files so that if i upload new files i don't have to modify the html page every time, is there any way to do that ?

解决方案

If you are using Apache as a web-server and have configured mod-autoindex for the directory you upload pdf files then you should probalby see somethink like this when navigation to that url:

This auto-generated page can be easily parsed by js using jquery:

var pdfFilesDirectory = '/uploads/pdf/';

// get auto-generated page 
$.ajax({url: pdfFilesDirectory}).then(function(html) {
    // create temporary DOM element
    var document = $(html);

    // find all links ending with .pdf 
    document.find('a[href$=.pdf]').each(function() {
        var pdfName = $(this).text();
        var pdfUrl = $(this).attr('href');

        // do what you want here 
    })
});

这篇关于列出网页中目录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆