(PECL mongo >=0.9.0)
MongoGridFS::storeUpload — Stores an uploaded file in the database
name
The name of the uploaded file(s) to store. This should correspond to the file field's name attribute in the HTML form.
metadata
Other metadata fields to include in the file document.
Замечание:
Данные поля могут перезаписать поля, автоматически созданные драйвером, как указано в основной документации MongoDB » коллекции файлов. В качестве практического применения данного поведения можно указать собственный chunkSize или _id для файла.
Замечание:
The filename field will be populated with the client's filename (e.g. $_FILES['foo']['name']).
Возвращает _id сохраненного документа. Это будет сгенерированный MongoId, за исключением случая, когда _id был явно указан в параметре metadata
.
Замечание:
If multiple files are uploaded using the same field name, this method will not return anything; however, the files themselves will still be processed.
Throws MongoGridFSException if there is an error reading the uploaded file(s) or inserting into the chunks or files collections.
Версия | Описание |
---|---|
1.2.5 | Changed second parameter to an array of metadata. Pre-1.2.5, the second parameter was an optional string overriding the filename. |
Пример #1 MongoGridFS::storeUpload() HTML form example
Suppose you have the following HTML form:
<form method="POST" enctype="multipart/form-data"> <label for="username">Username:</label> <input type="text" name="username" id="username" /> <label for="pic">Please upload a profile picture:</label> <input type="file" name="pic" id="pic" /> <input type="submit" /> </form>
If you wanted to store the uploaded image in MongoDB, you could do the following in the script handling the form submission:
<?php
$m = new MongoClient();
$gridfs = $m->selectDB('test')->getGridFS();
$gridfs->storeUpload('pic', array('username' => $_POST['username']));
?>