简体   繁体   English

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

[英]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. 我正在从$ _FILES中读取文件元数据,但不知道从哪里读取文件以存储在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路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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