I have the code bellow...in short it is mean't to generate a list of all files in a directory and then for every file in the list it would add a new gallery element to the page.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style media="screen">
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
</style>
</head>
<body>
<h1>Test</h1>
<script type="text/javascript">
var fs = require('fs');
var files = fs.readdirSync('uploads/');
for (item in files) {
document.write('<div class="gallery">');
document.write('<a target="_blank" href="uploads/'+item+'">');
document.write('<img src="uploads/'+item+'" width="600" height="400">');
document.write('</a>');
document.write('<div class="desc">'+item+'</div>');
document.write('</div>');
}
</script>
</body>
</html>
From some quick research var fs = require('fs');
and var files = fs.readdirSync('uploads/');
are supposed to get the files in the directory into the list and then the for
statement is mean't to add them to the page. However when I reload the page it remains blank. Does anyone have any ideas?