Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB GridFS image not loaded correctly
    primarykey
    data
    text
    <p>I am trying to save images to a MondoDB Collection using GridFS. To test this, I made the following:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;/head&gt; &lt;body&gt; &lt;?php // open connection $m = new MongoClient(); $db = $m-&gt;selectDB('ImageDatabase'); $gridUploads = $db-&gt;getGridFS('images'); // save image $fileName = 'C:\Users\Thomas\Pictures\commits.png'; $gridUploads-&gt;storeFile($fileName); // load image $doc = $gridUploads-&gt;findOne($fileName); // dsplay image header('Content-type: image/png'); echo $doc-&gt;getBytes(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This should upload the image to the collection and then get the same image from the collection and display it.</p> <p>The collection content after this is:</p> <pre><code>{ "_id" : ObjectId("52a6fcdd1dc38f0c3c0016bf"), "filename" : "C:\\Users\\Thomas\\Pictures\\commits.png", "uploadDate" : ISODate("2013-12-10T11:37:01.000Z"), "length" : 179952, "chunkSize" : 262144, "md5" : "768d618923442668ca2a60f02be59d52" } </code></pre> <p>print_r($doc):</p> <pre><code>MongoGridFSFile Object ( [file] =&amp;gt; Array ( [_id] =&amp;gt; MongoId Object ( [$id] =&amp;gt; 52a6fcdd1dc38f0c3c0016bf ) [filename] =&amp;gt; C:\Users\Thomas\Pictures\commits.png [uploadDate] =&amp;gt; MongoDate Object ( [sec] =&amp;gt; 1386675421 [usec] =&amp;gt; 0 ) [length] =&amp;gt; 179952 [chunkSize] =&amp;gt; 262144 [md5] =&amp;gt; 768d618923442668ca2a60f02be59d52 ) [gridfs:protected] =&amp;gt; MongoGridFS Object ( [w] =&amp;gt; 1 [wtimeout] =&amp;gt; 10000 [chunks] =&amp;gt; MongoCollection Object ( [w] =&amp;gt; 1 [wtimeout] =&amp;gt; 10000 ) [filesName:protected] =&amp;gt; images.files [chunksName:protected] =&amp;gt; images.chunks ) [flags] =&amp;gt; 0 ) </code></pre> <p>However the result's body content is:</p> <pre><code>&lt;img style="-webkit-user-select: none" src="http://localhost/path-to/the-script.php"&gt; </code></pre> <p>Any ideads why?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload