title: Display image from PostgreSQL database in PHP
body: <p>I want to display an image from my PostgreSQL database in a PHP file.
  After trying a lot of different possibilities, I don't get very far.
  Here is what I do:</p>
  
  <p>Upload:</p>
  
  <pre><code>echo "&lt;div&gt;".
      "&lt;table border=\"1\" cellpadding=\"3\"&gt;".
         "&lt;form action=\"test2.php\" method=\"post\" enctype=\"multipart/form-data\"&gt;".
           "&lt;tr&gt;".
             "&lt;td&gt;".
               "&lt;input type=\"file\" name=\"file\" id=\"file\"&gt;".
               "&lt;input class=\"button\" type=\"submit\" name=\"submit\" value=\"Submit\"&gt;".
             "&lt;tr&gt;".
           "&lt;/tr&gt;".
        "&lt;/form&gt;".
       "&lt;/table&gt;".
     "&lt;/div&gt;"; 
  </code></pre>
  
  <p>Display:</p>
  
  <pre><code>if(isset($_FILES['file'])) //file uploaded
  {
    $file_raw = file_get_contents($_FILES['file']['tmp_name']);
    $file     = pg_escape_bytea($file_raw);
    //Here is Code to insert into Database but just to test, I try it directly:
  
    header('Content-Type: image/png');
    echo pg_unescape_bytea($file);
  }
  </code></pre>
  
  <p>I already have the display part in an extra file and so on, but these are the essential information you need to know.</p>
  
  <p>I wont get any image displayed, just this "Broken Image" icon from the browser.
  What is wrong here? How can I solve this?
  Thank you!</p>