如何获取 cpanel 中文件夹内所有文件夹名称的列表?
How to get a list of all folder names inside a folder in cpanel?
我想获取 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;
?>
我在 /wp-content/plugins.
中将此文件另存为 "pluginlist.php"
您当前正在打印值,然后添加 headers。它需要反过来。此外,您正在检查 is_file()
但应该 is_dir()
检查。
<?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;
我想获取 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;
?>
我在 /wp-content/plugins.
中将此文件另存为 "pluginlist.php"您当前正在打印值,然后添加 headers。它需要反过来。此外,您正在检查 is_file()
但应该 is_dir()
检查。
<?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;