0

I am attempting to get a list of css files from a directory into a Wordpress Template. I am a trying to make the code below work with no luck. What am I doing wrong?

$path = parse_url(TC_BASE_URL . 'custom/css/', PHP_URL_PATH);
$dir = $_SERVER['DOCUMENT_ROOT'] . $path;
$dir = str_replace("/", "\\",$dir);
$dir = str_replace("\\\\", "\\",$dir);
if (is_dir($dir)) {
    if ($dh == opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    } else {
        echo $dir . ' Is Not Open';
    }
} else {
    echo $dir . ' Is Not A Directory';
}
Talon06
  • 1,756
  • 3
  • 27
  • 51

1 Answers1

1

I made the following test:

<?php
    $ruta = "C:\\www\\wp-content\\themes\\custom\\custom\\css\\";

    if (is_dir($ruta)) {
        if ($dh = opendir($ruta)) {
            while (($file = readdir($dh)) !== false) {
                echo "file name: $file : file type: " . filetype($ruta . $file) . "</br>";
            }
            closedir($dh);
        }
    }

?> 

The output:

file name: . : file type: dir
file name: .. : file type: dir
file name: Nuevo Documento de Microsoft Word.docx : file type: file
file name: Nuevo KuaiZip ZIP Archive file.zip : file type: file
Hackerman
  • 12,139
  • 2
  • 34
  • 45