簡體   English   中英

如何上傳文件並將其存儲在mongodb中?

[英]how to upload file and store it in mongodb?

在此示例中,“路徑”是服務器中(上傳的)臨時文件的路徑嗎? 或客戶端設備中的文件路徑? 我正在從$ _FILES中讀取文件元數據,但不知道從哪里讀取文件以存儲在db中。 請幫忙。 (對不起我的英語不好)

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