php-doc-en/reference/mongo/mongogridfs/storebytes.xml

144 lines
3.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongogridfs.storebytes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoGridFS::storeBytes</refname>
<refpurpose>Stores a string of bytes in the database</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>mixed</type><methodname>MongoGridFS::storeBytes</methodname>
<methodparam><type>string</type><parameter>bytes</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>metadata</parameter><initializer>array()</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>bytes</parameter>
</term>
<listitem>
<para>
String of bytes to store.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>metadata</parameter>
</term>
<listitem>
<para>
Other metadata fields to include in the file document.
</para>
&mongo.gridfs.store.metadata.note;
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>options</parameter>
</term>
<listitem>
<para>
An array of options for the insert operations executed against the
<literal>chunks</literal> and <literal>files</literal> collections. See
<function>MongoCollection::insert</function> for documentation on these
these options.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
&mongo.gridfs.store.return;
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoGridFSException</classname> if there is an error
inserting into the <literal>chunks</literal> or <literal>files</literal>
collections.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoGridFS::storeBytes</function> with additional metadata</title>
<programlisting role="php">
<![CDATA[
<?php
$m = new MongoClient();
$gridfs = $m->selectDB('test')->getGridFS();
$bytes = 'abcdefghijklmnopqrstuvwxyz';
$id = $gridfs->storeBytes($bytes, array('_id' => 'alphabet'));
$gridfsFile = $gridfs->get($id);
var_dump($gridfsFile->file);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(7) {
["_id"]=>
string(8) "alphabet"
["uploadDate"]=>
object(MongoDate)#7 (0) {
}
["length"]=>
int(26)
["chunkSize"]=>
int(262144)
["md5"]=>
string(32) "c3fcd3d76192e4007dfb496cca67e13b"
}
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>MongoGridFS::put</function></member>
<member><function>MongoGridFS::storeFile</function></member>
<member><function>MongoGridFS::storeUpload</function></member>
<member>MongoDB core docs on <link xlink:href="&url.mongodb.docs.gridfs;">GridFS</link></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->