如何用 JavaScript 编写此 PHP 代码?
我对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]\" />";
}
?>
最佳答案
考虑熟悉 nodejs 。它要求您有一个 serverside V8 JS engine安装在服务器上。这将允许您在服务器上使用 ECMAScript/JavaScript,例如列出服务器文件系统上的文件并从客户端查询。
- 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 '..'.
和
- fs.readdirSync(path)
Synchronous readdir(3). Returns an array of filenames excluding '.' and '..'.
您可能还对 phpjs 感兴趣,其目的是将 PHP 函数移植到 PHP(不过没有 scandir
,而且我真的不确定总体上对此有何看法)。
关于php - 我怎样才能用 JavaScript 编写这个 PHP 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4076869/