Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to bulletproof this image parser function
    text
    copied!<p>I've got a function below which reads the contents of wp-content/uploads and writes out all images that it finds there.</p> <p>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</p> <p>Blog title is abc123.com</p> <p>site url is abc123.com</p> <p>test image filename is abc123-1.jpg</p> <p>img tag SHOULD become: </p> <pre><code>&lt;img src='http://abc123.com/wp-content/uploads/abc123-1.jpg' /&gt; </code></pre> <p>actual image tag written from the function below is: </p> <pre><code>&lt;img src='http://abc123.com/wp-content/uploads/abc123.com-1.jpg' /&gt; </code></pre> <p>My question is, how did the ".com" get inserted into the filename???</p> <p>Function follows...</p> <pre><code> 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) &amp;&amp; preg_match("/\.(bmp|jpeg|gif|png|jpg|)$/i", $file)) { array_push($imgs, $file); } } closedir($dh); } else { die('cannot open ' . $dir); } foreach ($imgs as $idx=&gt;$img) { $class = ($idx == count($imgs) - 1 ? ' class="xlast"' : ''); echo '&lt;img src="' . $url . $img . '" alt="' .$img . '"' . $class . ' /&gt;'; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload