How can I write this PHP code in JavaScript
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.
See the API docs
- 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).
You can't read files from the server's file system using JavaScript.
Javascript runs on the browser, so you don't have access to server, unless you write some PHP code and AJAX to do that.
精彩评论