简体   繁体   English

fs.readdir 不检索文件

[英]fs.readdir not retrieving files

I want to make a JavaScript code that created dynamically a list of files that I have in a specific folder on my server.我想制作一个 JavaScript 代码,该代码动态创建我在服务器上特定文件夹中拥有的文件列表。 This list will be presented when I press a button and each object will have a checkbox.当我按下按钮时将显示此列表,并且每个对象都有一个复选框。 The selected items will then be downloaded with another submit button and I guess some PHP.然后将使用另一个提交按钮下载所选项目,我猜是一些 PHP。

So far I used JavaScript code I found online to find the names of the files and then call another function to create the elements but no luck.到目前为止,我使用我在网上找到的 JavaScript 代码来查找文件的名称,然后调用另一个函数来创建元素,但没有成功。 It seems that the function doesn't retrieve any files.该函数似乎没有检索任何文件。 Here is my code:这是我的代码:

function createEl(a){
    var myDiv = document.getElementById("cboxes");
    var checkBox = document.createElement("input");
    var label = document.createElement("label");
    checkBox.type = "checkbox";
    checkBox.value = a;
    myDiv.appendChild(checkBox);
    myDiv.appendChild(label);
    label.appendChild(document.createTextNode(a));

}
function foldlist(){
const testFolder = './xampp/htdocs/website1/uploads';
const fs = require('fs');

fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {`enter code here`
    var a=file;
    createEl(a);
  });
})}

as @str mentioned i mixed up frontend and backend javascript.正如@str 提到的,我混合了前端和后端 javascript。 Thank you all for the replies谢谢大家的回复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM