O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - serving images from GridFS

We are going to build two simple PHP pages, the first one will list all the images stored in the database in an HTML table. Clicking on any item on this list will take us to the second script that will output the image in the browser:

  1. Open a new file in the text editor and add the following PHP/HTML code to it:
    <?php require 'dbconnection.php'; $mongo = DBConnection::instantiate(); $gridFS = $mongo->database->getGridFS(); $objects = $gridFS->find(); ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Uploaded Images</title> <link rel="stylesheet" type="text/css" href="styles.css"/> </head> <body> <div id="contentarea"> <div id="innercontentarea"> <h1>Uploaded Images</h1> <table ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required