简体   繁体   English

读取Javascript中的文件夹名称

[英]Read folder names in Javascript

I want to read the folder names in a specific directory and create a dropdown list with the names. 我想读取特定目录中的文件夹名称,并使用名称创建一个下拉列表。 All files and folders are stored on a debian web-server (nginx, php5). 所有文件和文件夹都存储在debian网络服务器(nginx,php5)上。 Actual I do this with php, but I don't know much about php, so I want to do this with Javascript. 实际上,我使用php来做到这一点,但是我对php的了解不多,所以我想使用Javascript来做到这一点。 The php code looks like: php代码如下所示:

<?php
     foreach(glob('auswertung/*', GLOB_ONLYDIR) as $dir) {
        $dir = str_replace('auswertung/', '', $dir);
        $blacklist = array('.', '..', 'standard');
        $files = glob("auswertung/$dir/_*");
        if (!in_array($dir, $blacklist)){

             $dirSmall = substr($dir,0,10);
             $datum = date('d.m.Y - H:i:s', $dirSmall);
             foreach ($files as $file){
                 $file = str_replace("auswertung/$dir/_", '', $file);
                 $file_utf8 = utf8_encode($file );
                 $von = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é");  //to correct double whitepaces as well
                 $zu  = array("&auml;","&ouml;","&uuml;","&szlig;","&Auml;","&Ouml;","&Uuml;","&nbsp;","&#233;");  
                 $file2 = str_replace($von, $zu, $file_utf8);
              }
              echo '<option value="'.$dir.'">'.$datum." - ".$file2."</option>\n";

         }
     }
?>

The folders names are formated in Unix Timestamp, like 1413893713034, 1414926421959 ... Is it possible to do this in Javascript, because I have problems to combine HTML, Javascript and PHP? 文件夹名称采用Unix Timestamp格式,例如1413893713034、1414926421959 ...是否可以在Javascript中执行此操作,因为我在组合HTML,Javascript和PHP时遇到问题?

据我所知,简短的答案是“否”。您必须使用服务器端语言(例如PHP)来访问服务器的文件系统。

As other have said Javascript is loaded on a Client web page, it cannot directly access the server file structure. 正如其他人所说的,Javascript是加载在客户端网页上的,它不能直接访问服务器文件结构。

However you can "load" an Ajax response from a Server-Side page (like php or others) and then work with those Strings in the way you desire. 但是,您可以从服务器端页面(例如php或其他)“加载” Ajax响应,然后以所需的方式使用这些String。

As others have said you can't do this on client side. 正如其他人所说,您不能在客户端执行此操作。 The most elegant solution to achieve this is through AJAX. 实现此目的的最优雅的解决方案是通过AJAX。 Do you need a simple example of this? 您是否需要一个简单的例子?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM