Pull dedicated images from folder - show image + filename (strip part of filename + file-extension)
<p>based on the original code in <a href="http://stackoverflow.com/questions/5525677/showing-images-in-php/15047583">this question</a> and Tims correction over there (answer 1) I'm trying to achieve the following:</p>

<p>I have a folder "img" containing images as follows:</p>

<ul>
<li>image_123.jpg</li>
<li>image_123_alternate.jpg</li>
<li>image_456.jpg</li>
<li>image_456_alternate.jpg</li>
<li>image_789.jpg</li>
<li>image_789_alternate.jpg</li>
<li>and so on...<br />
(Note: all images have the same size of 200px/200px)</li>
</ul>

<p>When pulling from the "img" folder the simple HTML page should display images and filenames in the following fashion:</p>

<p>The actual images that contain the "_alternate" part in their filename (and only these) + the image filename not containing the "_alternate" part (without the file-extension) underneath the image in a textbox. All pairs should be pulled in an alphabetical order. In the example below bold capital letters indicate the actual image to be displayed:</p>

<p><b>IMAGE_123_ALTERNATE</b><br />
textbox: "image_123"</p>

<p><b>IMAGE_456_ALTERNATE</b><br />
textbox: "image_456"</p>

<p><b>IMAGE_789_ALTERNATE</b><br />
textbox: "image_789"</p>

<p>This is what I have so far but this displays all images and filenames:</p>

<pre><code>&lt;?php
$dir = opendir("img");
while (($file = readdir($dir)) !== false)
{
echo "&lt;a href='img/".$file."' target='_blank'&gt; &lt;img src='img/".$file."'width='200' height='200' /&gt;&lt;/a&gt;&lt;br /&gt;";
echo "&lt;textarea&gt;$file&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;";
}
closedir($dir);
?&gt; 
</code></pre>

<p>Any help would be much appreciated!</p>

<p>Thanks a lot!</p>
