<?php
//initialization Gridfs
$conn = new Mongo ();//Connection MongoDB
$db = $conn->photos;//Select database
$grid = $db-> Getgridfs (); Get Gridfs Object
Gridfs has three ways of storing files
The first type of direct storage file
$id = $grid->storefile ("./logo.png");
Second storage file binary stream
$data = Http://www.bkjia.com/PHPjc/get_file_contents ("./logo.png");
$id = $grid->storebytes ($data, Array ("Parame" => ' additional parameters will be deposited with the picture '));
The third type of file to save direct form submissions $_files
$id = $grid->storeupload (' upfile ');//equivalent to
$id = $grid->storefile ($_files[' upfile '] [' tmp_name ']);
--------------above is to save the picture--read the picture below----------------//
Save success return $id = MD5 string $logo = $grid->findone (Array (' _id ' = > $id));
The
header (' content-type:image/png ') of the file is obtained with _id as index;
Output image head
echo $logo->getbytes ();
Output data stream?>
Thank you for reading, I hope to help you, thank you for your support for this site!