A: 

You don't need the $count. This will give you the same result

$list[] = array();
while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
        $list[] = $file;
    }
}

Replace sorting and displaying with just:

sort($list);
for ($i = 0; $i < count($list); $i++) {
    echo "<li><img src=\"photos/{$list[$i]}\" alt=\"{$list[$i]}\" title=\"\"></li>\n";
}
RaYell
change $list[] = array() to $list = array(). also you want to use natsort(), instead of sort(). :-)
Philippe Gerber
+1  A: 

Try this:

$photos = glob('photos/*');
foreach($photos as $photo) {
    echo "<li><img src=\"{$photo}" alt=\"{$photo}\" title=\"\"></li>\n";

}

http://us.php.net/manual/en/function.glob.php

davethegr8
maybe glob('photos/*.jpg'); just to be sure.
Skilldrick
yeah, it you know they are jpgs it's a good idea to use the extension. But they could in theory be any one of several photo formats.
davethegr8
+2  A: 

You could take advantage of the scandir() function, which will handle reading the directory as well as sorting the results.

$files = scandir('photos');
if ($files !== false) 
{
    foreach($files as $f) {
     if ($f == '..' || $f == '.') continue;  
        echo '<li><img src="photos/'.$f.'" alt="'.$f.'" title=""></li>'."\n";
    }
}

I edited it a bit for readability.

zombat
A: 

You can replace

foreach ($sorted_list as $i => $value) {
    echo "<li><img src=\"photos/$sorted_list[$i]\" alt=\"$sorted_list[$i]\" title=\"\"></li>\n";
  }

with

foreach ($sorted_list as $value) {
    echo "<li><img src=\"photos/$value\" alt=\"$value\" title=\"\"></li>\n";
}

Then you don't need to call array_values(), because it doesn't matter that the array keys aren't in numeric order.

Tom Haigh
A: 

A simplier way is using the scandir function:

$dir = 'photos';
$files = array_diff( scandir($dir), array(".", "..") );
foreach ($files as $i => $value) {
    echo "<li><img src=\"photos/$value\" alt=\"$value\" title=\"\"></li>\n";
}

good luck!

inakiabt