How can I write this PHP code in JavaScript?
I have no knowledge about JavaScript... :-s
<?php
$pozethumb=scandir("./pics/flori/thumbs");
$size=count($pozethumb);
$nrpoze=$size-2;
for($i=2;$i<$size;$i++)
{
echo"<img src=\"./pics/flori/thumbs/$pozethumb[$i]\" class=\"thumb\" sou=\"$pozethumb[$i]\" />";
}
?>
Consider familiarizing yourself with nodejs. It requires you to have a serverside V8 JS engine installed on the server. This would allow you to use ECMAScript/JavaScript on the server, e.g. list files on the filesystem of the server and query it from the client.
- fs.readdir(path, [callback])
Asynchronous readdir(3). Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.
and
- fs.readdirSync(path)
Synchronous readdir(3). Returns an array of filenames excluding '.' and '..'.
You might also be interested in phpjs, which aims to port PHP functions to PHP (doesnt have scandir
though and I'm really not sure what to think of that in general anyway).