I've got a function below which reads the contents of wp-content/uploads and writes out all images that it finds there.
The problem is that it's reading off the blog title to determine the image path and when the blog title has a dot in it, there's trouble
Blog title is abc123.com
site url is abc123.com
test image filename is abc123-1.jpg
img tag SHOULD become:
<img src='http://abc123.com/wp-content/uploads/abc123-1.jpg' />
actual image tag written from the function below is:
<img src='http://abc123.com/wp-content/uploads/abc123.com-1.jpg' />
My question is, how did the ".com" get inserted into the filename???
Function follows...
function get_images()
{
global $options;
foreach ($options as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
if($cb_custom_images !== "")
{
echo $cb_custom_images;
}
else
{
$dir = 'wp-content/uploads/';
$url = get_bloginfo('url').'/wp-content/uploads/';
$imgs = array();
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (!is_dir($file) && preg_match("/\.(bmp|jpeg|gif|png|jpg|)$/i", $file))
{
array_push($imgs, $file);
}
}
closedir($dh);
} else {
die('cannot open ' . $dir);
}
foreach ($imgs as $idx=>$img)
{
$class = ($idx == count($imgs) - 1 ? ' class="xlast"' : '');
echo '<img src="' . $url . $img . '" alt="' .$img . '"' . $class . ' />';
}
}
}