I'm using PHP to grab a series of photos from a folder and display them on the page. For some reason, I can't get it to pull the images in the right order. You'd think they'd get pulled in numerical/alphabetical order, but they seem to load in the same nonsensical order every time I remove and re-upload the photos to the folder. ( 003, 009, 001, 011...) I just want them to get pulled and display in some logical order.
I'm using the following code:
<?php
$images = "photos/sym/"; # Location of the photos
$cols = 1; # Number of columns to display
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo '<table width="100%" cellspacing="0"><tr>';
foreach($files as $file)
{
if($colCtr %$cols == 0)
echo '</tr><td align="center"><div class="item"><img src="' . $images . $file . '"></div></td>';
$colCtr++;
}
echo '</table>' . "\r\n";
?>
I'm using the following code:
<?php
$images = "photos/sym/"; # Location of the photos
$cols = 1; # Number of columns to display
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo '<table width="100%" cellspacing="0"><tr>';
foreach($files as $file)
{
if($colCtr %$cols == 0)
echo '</tr><td align="center"><div class="item"><img src="' . $images . $file . '"></div></td>';
$colCtr++;
}
echo '</table>' . "\r\n";
?>