Created
May 17, 2012 21:13
-
-
Save imjacobclark/2721622 to your computer and use it in GitHub Desktop.
GridFS MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$m = new Mongo(); | |
$db = $m->database; | |
$collection = $db->images; | |
$cursor = $collection->find(); | |
foreach ($cursor as $obj) { | |
$unique_id = $obj['test']; | |
echo "<img src='newupload.php?unique_id=".$unique_id."'>"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": ObjectId("4fb43613ee3c47c31e000002"), | |
"files_id": ObjectId("4fb43613ee3c47c31e000001"), | |
"n": 0, | |
"data": "<Mongo Binary Data>" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": ObjectId("4fb43613ee3c47c31e000001"), | |
"chunkSize": 262144, | |
"filename": "1335567298_4.png", | |
"length": 11077, | |
"md5": "3c180a7e5c06210065a83db581ac24b1", | |
"test": "test3", | |
"uploadDate": ISODate("2012-05-16T23: 19: 47.473Z"), | |
"username": "joe" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
$posted_id = $_GET['unique_id']; | |
$conn = new Mongo; | |
$db = $conn->database; | |
$grid = $db->getGridFS(); | |
$file = $grid->findOne(array('test' => $posted_id)); | |
echo $file->getBytes(); | |
exit; | |
$conn->close(); | |
}catch(MongoConnectionException $e){ | |
die('Error connecting to MongoDB server'); | |
}catch(MongoException $e){ | |
die('Error: ' . $e->getMessage()); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment