简体   繁体   中英

how to upload file and store it in mongodb?

in this example "path" is path to (uploaded)temporary file in server? or file path in client's device? i'm reading files metadata from $_FILES but don't know where to read the file to store in db. please help. (sorry for my english)

<?php
    // connect to the ‘myGrid’ GridFS
    $m = new Mongo();
    $db = $m->myDB;
    $myGrid = $db->getGridFS('myGrid');
    $some_file='path of your video or audio file';
    // some extra data you may want to store with your file
    $data_array = array(
        'mime' => mime_content_type($some_file),
        'timestamp' => time(),
    );

    // store a file into the GridFS
    $myGrid->storeFile($some_file, $data_array);
?>

它是您要放入任何文件的路径,在这种情况下,它将是PHP $_FILES数组中的tmp_name路径

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM