Pregunta

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?

¿Fue útil?

Solución

** 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);
    }
}?>

Otros consejos

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

$dir = '/path/to/document/root/sandbox/Images';
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top