Copy CodeThe code is as follows:
Initialize Gridfs
$conn = new Mongo (); Connect to MongoDB
$db = $conn->photos; Select Database
$grid = $db->getgridfs (); Get Gridfs Object
Gridfs There are three ways to store files
The First Direct storage file
$id = $grid->storefile ("./logo.png");
Second binary stream for storage of files
$data = Get_file_contents ("./logo.png");
$id = $grid->storebytes ($data, Array ("Parame" + + ' additional parameters will be saved with the image));
The third file to save direct form submissions $_files
$id = $grid->storeupload (' upfile ');
Equivalent
$id = $grid->storefile ($_files[' upfile ' [' tmp_name ']);
--------------above is to save the picture--start reading the picture below----------------
return $id = MD5 string after successful save
$logo = $grid->findone (Array (' _id ' = $id)); Get the file with the _id index
Header (' content-type:image/png '); Output Image Header
echo $logo->getbytes (); Output data stream
?>
http://www.bkjia.com/PHPjc/327718.html www.bkjia.com true http://www.bkjia.com/PHPjc/327718.html techarticle Copy the code as follows: PHP//Initialize Gridfs $conn = new Mongo ();//Connect MongoDB $db = $conn-photos;//Select Database $grid = $db-getgridfs (); Gridfs object//gridfs have ...