Reading up on scandir(), having an issue getting anything to display.

<?php
    $dir = 'http://www.universaldynamicmedia.com/sandbox/Images';
    $array = scandir($dir);
    foreach($array as $key => $value)
        {
            echo '<li><img src="' . $dir . $value . '" /></li>';
        }
?>

I supposed I'm not doing something right with the directory and scandir() as the other stuff, I've done before and it works fine.

Would directory permissions cause an issue?

有帮助吗?

解决方案

** Note you cannot use a URL, you must have access to the folders/files

scandir():

$dir = "PATH_TO_DIRECTORY";
$exclude = array( ".","..","error_log","_notes" );
if (is_dir($dir)) {
    $files = scandir($dir);
    foreach($files as $file){
        if(!in_array($file,$exclude)){
            echo '<li><img src="' . $dir . $file . '" /></li>';
        }
    }
}

readdir():

$dir = "PATH_TO_DIRECTORY";
$exclude = array( ".","..","error_log","_notes" );
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if(!in_array($file,$exclude))
                 echo '<li><img src="' . $dir . $file . '" /></li>';
        }
        closedir($dh);
    }
}?>

其他提示

scandir() only works on local filesystems, you need to change that to:

$dir = '/path/to/document/root/sandbox/Images';
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top