简体   繁体   中英

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). Actual I do this with php, but I don't know much about php, so I want to do this with Javascript. The php code looks like:

<?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?

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

As other have said Javascript is loaded on a Client web page, it cannot directly access the server file structure.

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.

As others have said you can't do this on client side. The most elegant solution to achieve this is through AJAX. Do you need a simple example of this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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