title: Displaying images retrieved from mongodb in web browser?
body: <p>I am trying to retrieve an image from mongoDB and display it in web browser. But it is not working. Here is the code which I am using for insertion and retrieval</p>
  
  <p>Code to upload:</p>
  
  <pre><code>&lt;?php
  //If you wanted to store the uploaded image in MongoDB, you could do the following in the script handling the form submission: 
  if(isset($_REQUEST['formsubmit']))
  {
      $m = new MongoClient();
      $coll = $m-&gt;test;
      $gridFS = $coll-&gt;getGridFS();
      $tag = $_REQUEST['username'];
      $gridFS-&gt;storeUpload('pic',array("tag"=&gt;$tag));
      echo 'File Uploaded Successfully';
      $m-&gt;close();
  }
  ?&gt;
  &lt;!-- image and any file  uploaded  in mongodb --&gt;
  &lt;html&gt;
  &lt;head&gt; Upload Image&lt;/head&gt;
  &lt;body&gt;
  &lt;!--The name of the uploaded file to store. This should correspond to the file field's name attribute in the HTML form. --&gt;
      &lt;form method="POST" enctype="multipart/form-data"&gt;
          &lt;label for="username"&gt;Username:&lt;/label&gt;
          &lt;input type="text" name="username" id="username" /&gt;
          &lt;label for="pic"&gt;Please upload a profile picture:&lt;/label&gt;
          &lt;input type="file" name="pic" id="pic" /&gt;
          &lt;input type="submit" value="Register" name="formsubmit"/&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Code to retrieve image and display in browser:</p>
  
  <pre><code>&lt;?php
  //If you wanted to store the uploaded image in MongoDB, you could do the following in the script handling the form submission: 
      $m = new MongoClient();
      $coll = $m-&gt;test;
      $gridFS = $coll-&gt;getGridFS();
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;Displaying Image&lt;/head&gt;
  &lt;body&gt;
  &lt;?php
      header('content-type: image/jpg');
      echo '&lt;img src=' . $gridFS-&gt;findOne(array("tag"=&gt;"temp123"))-&gt;getBytes() .'&gt;'. '&lt;/img&gt;';
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Could anyone please help me out ??
  Thank you</p>