Directory question in PHP?

Can someone help me with this, I'm stuck. I don't know why this is not working

$myPath = get_bloginfo('wpurl').'/wp-content/uploads/'; // this is full path

function ReadDirList($d){
    $dir = opendir($d);
    $fs = "";
    while($folder = readdir($dir))
    {
        //if(is_dir($folder)){
            $fs = $fs. '<option>'.$folder.'</option>';
        //}
    }
    closedir($dir);
    echo $fs;
}

I call this <select> <?php ReadDirList($myPath); ?> </select> tnx function in advance.

+3
source share
1 answer

According to the link to the function, it get_bloginfo('wpurl')will return the URL. If you want to access the local file system, you need a real file path, not a URL.

Try this for the first line:

$myPath = WP_CONTENT_DIR.'/uploads/'; // this is full path

WP_CONTENT_DIRdefined in the configuration file and should point to wp-contentyour installation folder .

+2
source

Source: https://habr.com/ru/post/1742359/


All Articles