2017-09-11 3 views
0

Die Verwendung von opt.text(dir.substr(dir.lastIndexOf("\\")+1)); verursacht Problem in UNIX-System.Aber in Windows funktioniert es einwandfrei. Unter UNIX muss es "/" sein. Wie kann ich es für die Verwendung in Windows- und Unix-basierten Systemen kompatibel machen?Ausgabe von "//" in UNIX

+1

See [RecursiveDirectoryIterator] (https://secure.php.net/manual/en/class.recursivedirectoryiterator.php). –

+0

Fast ein Duplikat von https://stackoverflow.com/questions/14304935/php-listing-all-directories-and-sub-directories-recursively-in-drop-down-menu. Die Antwort sollte mit ein wenig Modifikation funktionieren, um Dateien anstelle von Verzeichnissen zu erhalten. –

Antwort

0

Ich benutze diesen Stil:

$dir = "/root/"; // Root directory to start at 

function scanServer($dir){ 
    global $totalList; 
    global $fileList; 
    global $dirList; 
    global $pathList; 

    $files = scandir($dir);    // Obtain all files into an array 
    foreach($files as $file){ 

     if($file != '.' && $file != '..'){ 
     if(is_dir($dir.'/'.$file)){  // Run self if it is a directory 
      $dirList[] = $file;    // Creates a master list of all directories 
      scanServer($dir.'/'.$file); 
     }else{ 
      $fileList[] = $file;   // Creates a master list of all files 
      $pathList[] = $dir.'/'.$file; // Creates a master list of absolute paths 

     } 
     } 
    } 
    } 

foreach($fileList as file){ 

    echo "<option value='".$file.">".$file."/>"; 
}