title: Displaying images in PHP?
body: <p>I have a webpage that I want to dynamically display content depending on the path of the page. For example, I may want <code>http://www.page.php?input=red</code> or maybe I'll want <code>http://www.page.php?input=blue</code>. In both cases, the actual content is located in <code>./$dir/</code>. </p>
  
  <p>I've got the gist of this down, but I can't for the life of me figure out images. I have an image in each directory at <code>./$dir/subdir/images/sample.png</code>. How do I output HTML that dynamically alters the image element? </p>
  
  <p>Here is sample code to demonstrate my question.</p>
  
  <pre><code>&lt;html&gt;
      &lt;?php
          $dir = $_GET["input"];
          $img = imagecreatefrompng("./$dir/subdir/images/sample.png");
      ?&gt;
      &lt;body&gt;
          &lt;img src="???" alt="sample image" /&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I want to display <code>./red/subdir/images/sample.png</code> when I have <code>input=red</code>, <code>./blue/subdir/images/sample.png</code> when <code>input=blue</code>, etc.</p>
  
  <p>Many thanks in advance for any help.</p>
  
  <p>Edit:<br>
  I don't even know if I can store an image into a variable as seen on line 4. I'm really new to PHP.</p>