Search code examples
javascriptphpfilesystemsreaddiropendir

PHP iterate over directory files


I have this simple code

if ($hdcss = opendir($javascript)) {

    while (false !== ($cssentry = readdir($hdcss))) {
        echo "$cssentry\n";
    }

    closedir($hdcss);
}

This will give out all files... What I want to do since I'll be getting this via Ajax is return an html string of li elements only JavaScript method is a for loop and not sure if this is done in php with opendir since this is my first time using this...

JavaScript Method:

var arry = [];

for(i=0;i<cssentry.length;i++){
    arry.push('<li>'+cssentry[i]+'</li>');
}

return arry.join(',');

If any suggestions, I'll take them.

Directory Path:

$javascript = "/cloud/'$username'/javascript/";
$css = "/cloud/'$username'/css/";

Solution

  • Directory Path:

    $javascript = "/cloud/'$username'/javascript/";
    $css = "/cloud/'$username'/css/";
    

    Directory Paths were in correct... the first forward slash is not needed