Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mongogridfs.storeupload(3) [php man page]

MONGOGRIDFS.STOREUPLOAD(3)						 1						MONGOGRIDFS.STOREUPLOAD(3)

MongoGridFS::storeUpload - Stores an uploaded file in the database

SYNOPSIS
public mixed MongoGridFS::storeUpload (string $name, [array $metadata]) DESCRIPTION
PARAMETERS
o $name - The name of the uploaded file(s) to store. This should correspond to the file field's name attribute in the HTML form. o $metadata - Other metadata fields to include in the file document. Note These fields may also overwrite those that would be created automatically by the driver, as described in the MongoDB core documentation for the files collection. Some practical use cases for this behavior would be to specify a custom chunkSize or _id for the file. Note The filename field will be populated with the client's filename (e.g. $_FILES['foo']['name']). RETURN VALUES
Returns the _id of the saved file document. This will be a generated MongoId unless an _id was explicitly specified in the $metadata param- eter. Note If multiple files are uploaded using the same field name, this method will not return anything; however, the files themselves will still be processed. ERRORS
/EXCEPTIONS Throws MongoGridFSException if there is an error reading the uploaded file(s) or inserting into the chunks or files collections. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 1.2.5 | | | | | | | Changed second parameter to an array of meta- | | | data. Pre-1.2.5, the second parameter was an | | | optional string overriding the filename. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 MongoGridFS.storeUpload(3) 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'])); ?> SEE ALSO
MongoGridFS.put(3), MongoGridFS.storeBytes(3), MongoGridFS.storeFile(3), MongoDB core docs on GridFS. PHP Documentation Group MONGOGRIDFS.STOREUPLOAD(3)

Check Out this Related Man Page

MONGOCOLLECTION.FINDONE(3)						 1						MONGOCOLLECTION.FINDONE(3)

MongoCollection::findOne - Queries this collection, returning a single element

SYNOPSIS
public array MongoCollection::findOne ([array $query = array()], [array $fields = array()], [array $options = array()]) DESCRIPTION
As opposed to MongoCollection.find(3), this method will return only the first result from the result set, and not a MongoCursor that can be iterated over. PARAMETERS
o $query - The fields for which to search. MongoDB's query language is quite extensive. The PHP driver will in almost all cases pass the query straight through to the server, so reading the MongoDB core docs on find is a good idea. Warning Please make sure that for all special query operaters (starting with $) you use single quotes so that PHP doesn't try to replace "$exists" with the value of the variable $exists. o $fields - Fields of the results to return. The array is in the format array('fieldname' => true, 'fieldname2' => true). The _id field is always returned. o $options - This parameter is an associative array of the form array("name" => <value>, ...). Currently supported options are: o "maxTimeMS"Specifies a cumulative time limit in milliseconds for processing the operation (does not include idle time). If the operation is not completed within the timeout period, a MongoExecutionTimeoutException will be thrown. RETURN VALUES
Returns record matching the search or NULL. ERRORS
/EXCEPTIONS Throws MongoConnectionException if it cannot reach the database. CHANGELOG
+--------+------------------------------------+ |Version | | | | | | | Description | | | | +--------+------------------------------------+ | 1.5.0 | | | | | | | Added optional $options argument. | | | | +--------+------------------------------------+ EXAMPLES
Example #1 MongoCollection::findOne document by its id. This example demonstrates how to find a single document in a collection by its id. <?php $articles = $mongo->my_db->articles; $article = $articles->findOne(array('_id' => new MongoId('47cc67093475061e3d9536d2'))); ?> Example #2 MongoCollection::findOne document by some condition. This example demonstrates how to find a single document in a collection by some condition and limiting the returned fields. <?php $users = $mongo->my_db->users; $user = $users->findOne(array('username' => 'jwage'), array('password')); print_r($user); ?> The above example will output something similar to: Array ( [_id] => MongoId Object ( ) [password] => test ) Notice how even though the document does have a username field, we limited the results to only contain the password field. SEE ALSO
MongoCollection.find(3), MongoCollection.insert(3), MongoDB core docs on find.. PHP Documentation Group MONGOCOLLECTION.FINDONE(3)
Man Page