简体   繁体   中英

How to get a list of all folder names inside a folder in cpanel?

I would like to get the names of all folders inside a folder in Cpanel. In my wordpress website, I need to get all the folder names (names of plugins) in public_html/wp-content/plugins to be saved into a text file which is located inside the root folder. How do I achieve this?

I tried with the following code, but it doesn't work.

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

I saved this file as "pluginlist.php" inside /wp-content/plugins.

You are currently printing values and then adding headers. It needs to be the other way round. Also, you are checking for is_file() but should rather be is_dir() check.

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

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