如何上传文件并将其存储在MongoDB中


how to upload file and store it in mongodb?

在此示例中,"路径"是服务器中(上传的)临时文件的路径? 还是客户端设备中的文件路径? 我正在从 $_FILES 读取文件元数据,但不知道在哪里读取要存储在数据库中的文件。 请帮忙。(对不起我的英语)

<?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路径