简体   繁体   English

如何在javascript中获取同级文件夹名称?

[英]How to get the sibling folder name in javascript?

You can see the folder structure here: 您可以在此处查看文件夹结构:

Fruit

Apple - index.html Apple - index.html

Orange - index.html Orange - index.html

Banana - index.html Banana - index.html

There is a root folder Fruit and three sub-folders. 有一个根文件夹Fruit和三个子文件夹。

I want to put the names Orange and Banana in Apple/index.html . 我想在Apple/index.html输入名称OrangeBanana

Is there any possible way to get the sibling folder names with javascript? 有没有可能用javascript获取同级文件夹名称?

Please help! 请帮忙!

Is there any possible way to get the sibling folder names with javascript? 有没有可能用javascript获取同级文件夹名称?

No. its not possible to get filesystem information with javascript 否。无法使用javascript获取文件系统信息

get a list of all folders in directory 获取目录中所有文件夹的列表

You could however load these names in first with PHP (Out of your database for example) or have them stored into a JSON (Javascript Object) file you have saved on your root 但是,您可以首先使用PHP加载这些名称(例如,从数据库中退出),或者将它们存储到保存在根目录下的JSON(Javascript对象)文件中

Quick solution: (Have not tested personaly) 快速解决方案:(未经个人测试)

<?php    
    $filesAndDirectories = scandir("..");
    foreach($filesAndDirectories as $fileOrDirectory){
        if(is_dir($fileOrDirectory)){
            echo "<a href='http://www.siteNameHere.com/". $fileOrDirectory ."/index.php'>". $fileOrDirectory ."</a>";
        }
    }

?>

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

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