<?php //初始化gridfs $conn = new Mongo(); //连接MongoDB $db = $conn->photos; //选择数据库 $grid = $db->getGridFS(); //取得gridfs对象
gridfs has three ways to store files
The first one stores files directly
$id = $grid->storeFile("./logo.png");
The second one stores file binary stream
$data = http://www.bkjia.com/PHPjc/get_file_contents("./logo.png");
$id = $grid->storeBytes($data,array("parame"=> 'Additional parameters will be stored together with the picture'));
The third way to save files submitted directly through the form $_FILES
$id = $grid->storeUpload('upfile');//相当于 $id = $grid->storeFile($_FILES[‘upfile'][‘tmp_name']); //--------------以上是保存图片--下面开始读取图片----------------// 保存成功后返回$id = md5字符串$logo = $grid->findOne(array('_id'=>$id)); //以_id为索引取得文件 header('Content-type: image/png'); //输出图片头 echo $logo ->getBytes(); //输出数据流?>
Thanks for reading, I hope it can help everyone, thank you for your support of this site !
For more detailed explanations of PHP MongoDB GridFS file storage methods and related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor