Skip to content

Instantly share code, notes, and snippets.

@sharpred
Created May 23, 2012 12:00

Revisions

  1. sharpred revised this gist May 23, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion getMongoAttachment.php
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,6 @@
    //iterate through the collection and retrieve the named file
    $grid = $database->getGridFS();
    foreach ($items as $item => $value) {
    //echo "$item: ";
    $fileName =$value["metadata"]["uploaddata"]["filename"];
    // md5 represents a unique key for a file so is a good one to use
    $md5 = $value["md5"];
  2. sharpred created this gist May 23, 2012.
    19 changes: 19 additions & 0 deletions getMongoAttachment.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php
    $mongoDB = new Mongo();
    $database = $mongoDB->selectDB("BVS");
    $collection = $database->createCollection('fs.files');
    //to get the attachments metadata back
    $query = array("metadata.formdata.claimid" => "SUS14052012-001");
    // $items is a cursor of mongodata
    $items = $collection->find($query);
    //iterate through the collection and retrieve the named file
    $grid = $database->getGridFS();
    foreach ($items as $item => $value) {
    //echo "$item: ";
    $fileName =$value["metadata"]["uploaddata"]["filename"];
    // md5 represents a unique key for a file so is a good one to use
    $md5 = $value["md5"];
    $file = $grid->findOne(array("md5" => $md5));
    $target = './' . $fileName;
    $file->write($target);
    }?>