so i found a bit of code to display all images in a chosen directory, it goes something like this:
but i keep getting the 'cannot open' message. my images are in mywebsite.com/r/ so i set the dir as /r/ but i can't figure out why it's not able to open the dir. any ideas?PHP Code:<?php
$dir = '/r/';
$imgs = array();
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (!is_dir($file) && preg_match("/\.(bmp|jpe?g|gif|png)$/", $file)) {
array_push($imgs, $file);
}
}
closedir($dh);
} else {
die('cannot open ' . $dir);
}
foreach ($imgs as $idx=>$img) {
$class = ($idx == count($imgs) - 1 ? ' class="last"' : '');
echo '<img src="' . $dir . $img . '" alt="' .
$img . '"' . $class . ' />' . "\n";
}
?>



Reply With Quote
Bookmarks