title: PHP rendering image from a class function
body: <p>I have a simple routing system where a request to the controller class is being sent using the following format:</p>
  
  <pre><code>http://localhost/dispatcher.php/some/path/to/needed/file
  </code></pre>
  
  <p>One of the controllers is used to process all requests to get media and asset files such as css, javascript and images.  Class member function that renders these assets like so (css content type is shown):</p>
  
  <pre><code> public function showAsset($request_path) {
       if (file_exists($request_path)) {
           header('Content-type: text/css');
           readfile($file);
  }  
  </code></pre>
  
  <p>So this works fine with text based files such css and javascript (with text/script header of course), however, when content type</p>
  
  <pre><code>header('Content-type: image/png');
  </code></pre>
  
  <p>is specified, the browser shows broken image icon. </p>
  
  <p>Image exists, it shows up fine in the browser if I access it directly bypassing the router.  There is no errors in the server log.  And it works fine if I use this code outside of the application in a test file:</p>
  
  <pre><code>&lt;?php
  class testClass
  {
      public function show()
      {
          $file='test.png';
          header('Content-Type: image/png');
          readfile($file);
      }
  }
  
  $t=new testClass();
  $t-&gt;show();
  ?&gt;
  </code></pre>
  
  <p>Has anyone encountered something like this before?  I'm wondering if the issue has something to do with extra headers or session variables that are getting set somewhere else in the app prior to routing, but I am not sure where to look.</p>