PHP operation MongoDB Gridfs storage File _php Tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.