Php 如何在cpanel中获取文件夹中所有文件夹名称的列表?

Php 如何在cpanel中获取文件夹中所有文件夹名称的列表?,php,wordpress,cpanel,Php,Wordpress,Cpanel,我想在Cpanel中获取文件夹中所有文件夹的名称。在我的wordpress网站中,我需要将public_html/wp content/plugins中的所有文件夹名称(插件名称)保存到根文件夹中的文本文件中。我如何做到这一点 我尝试了以下代码,但不起作用 <?php $files = scandir($dir,0); foreach ($files as $value) { if ($value > "0" && is_file($value)){

我想在Cpanel中获取文件夹中所有文件夹的名称。在我的wordpress网站中,我需要将public_html/wp content/plugins中的所有文件夹名称(插件名称)保存到根文件夹中的文本文件中。我如何做到这一点

我尝试了以下代码,但不起作用

<?php
$files = scandir($dir,0);
 foreach ($files as $value) {
      if ($value > "0" && is_file($value)){
      print $value . "\n";}}

    header('Content-Type: text/plain; charset=utf-8');
    header('Content-Disposition: attachment; filename="pluginlist.txt"');
    readfile($value);
exit;
?>

您当前正在打印值,然后添加标题。它需要反过来。另外,您正在检查
是否为is_file()
,但应该检查


opendir
scandir
功能?是的,但我不太清楚。你说的是Cpanel中文件夹内所有子文件夹的名称。那么,你也想递归地迭代子文件夹吗?不,我是说插件文件夹中的文件夹。我将编辑这个问题。如果你想创建一个WordPress插件,你需要几行代码才能让它工作。《官方指南》是一个很好的起点:@Ajesh很乐意帮忙
<?php

header('Content-Type: text/plain; charset=utf-8');
header('Content-Disposition: attachment; filename="pluginlist.txt"');


foreach (array_diff(scandir(__DIR__),array(".","..")) as $value) {
    if (is_dir($value)){
        echo $value . "\n";
    }
}

exit;