php - 我怎样才能用 JavaScript 编写这个 PHP 代码

标签 php javascript phpjs

如何用 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,例如列出服务器文件系统上的文件并从客户端查询。

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 '..'.

  • 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/

相关文章:

javascript - 带有 SQLSRV 和 JSON 的 jQuery 数据表

javascript - AngularJS:WAITING $scope 函数内的 ng-click 事件

javascript - Javascript 测试用例中的虚假字符 : all breaks

php - 与 PHP.js Javascript 库集成

php - array_unique 和 preg_split PREG_SPLIT_NO_EMPTY 的等效项

c# - 用户凭据在 asp.net 网站中以明文形式发送

php - SQL 排序规则未正确显示

javascript - 我如何提交我的 jquery 模态表单

javascript - 按反值引用列出的元素

javascript - JavaScript 中缺少分号导致 "' foo' 在 IE9 中未定义”错误