Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 9502

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Stores a file in the database</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongogridfs.storebytes.html">MongoGridFS::storeBytes</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongogridfs.storeupload.html">MongoGridFS::storeUpload</a></div>
 <div class="up"><a href="class.mongogridfs.html">MongoGridFS</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongogridfs.storefile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoGridFS::storeFile</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.0)</p><p class="refpurpose"><span class="refname">MongoGridFS::storeFile</span> &mdash; <span class="dc-title">Stores a file in the database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongogridfs.storefile-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>MongoGridFS::storeFile</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$metadata</code><span class="initializer"> = array()</span></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = array()</span></span>
  ]] )</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongogridfs.storefile-parameters">
 <h3 class="title">Parameters</h3>
 <p class="para">
  <dl>

   <dt>

    <span class="term">
     <em><code class="parameter">filename</code></em>
    </span>
    <dd>

     <p class="para">
      Name of the file to store.
     </p>
    </dd>

   </dt>

   <dt>

    <span class="term">
     <em><code class="parameter">metadata</code></em>
    </span>
    <dd>

     <p class="para">
      Other metadata fields to include in the file document.
     </p>
     <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">These fields may also overwrite those that would be created automatically by the driver, as described in the MongoDB core documentation for the <a href="http://docs.mongodb.org/manual/core/gridfs/#the-files-collection" class="link external">&raquo;&nbsp;files collection</a>. Some practical use cases for this behavior would be to specify a custom <em>chunkSize</em> or <em>_id</em> for the file.</p></p></blockquote>
    </dd>

   </dt>

   <dt>

    <span class="term">
     <em><code class="parameter">options</code></em>
    </span>
    <dd>

     <p class="para">
      Options for the store.
      <ul class="itemizedlist">
       <li class="listitem"><p class="para"><em>&quot;w&quot;</em></p><p class="para">See <a href="mongo.writeconcerns.html" class="link">WriteConcerns</a>. The default value for <a href="class.mongoclient.html" class="classname">MongoClient</a> is <em>1</em>.</p></li>
      </ul>
     </p>
    </dd>

   </dt>

  </dl>

 </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongogridfs.storefile-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">Returns the <em>_id</em> of the saved file document. This will be a generated <a href="class.mongoid.html" class="classname">MongoId</a> unless an <em>_id</em> was explicitly specified in the <em><code class="parameter">extra</code></em> parameter.</p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongogridfs.storefile-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">Throws <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> if the &quot;w&quot; option is set and the write fails.</p><p class="para">Throws <a href="class.mongocursortimeoutexception.html" class="classname">MongoCursorTimeoutException</a> if the &quot;w&quot; option is set to a value greater than one and the operation takes longer than <var class="varname"><var class="varname">MongoCursor::$timeout</var></var> milliseconds to complete.  This does not kill the operation on the server, it is a client-side timeout. The operation in <em>MongoCollection::$wtimeout</em> is milliseconds.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongogridfs.storefile-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1507">
   <p><strong>Example #1  <span class="function"><strong>MongoGridFS::storeFile()</strong></span> with additional metadata</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$gridfs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">selectDB</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getGridFS</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gridfs</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">storeFile</span><span style="color: #007700">(</span><span style="color: #DD0000">'example.txt'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'contentType'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'plain/text'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$gridfsFile&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gridfs</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$gridfsFile</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">file</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(7) {
  [&quot;_id&quot;]=&gt;
  object(MongoId)#6 (0) {
  }
  [&quot;contentType&quot;]=&gt;
  string(10) &quot;plain/text&quot;
  [&quot;filename&quot;]=&gt;
  string(11) &quot;example.txt&quot;
  [&quot;uploadDate&quot;]=&gt;
  object(MongoDate)#7 (0) {
  }
  [&quot;length&quot;]=&gt;
  int(26)
  [&quot;chunkSize&quot;]=&gt;
  int(262144)
  [&quot;md5&quot;]=&gt;
  string(32) &quot;c3fcd3d76192e4007dfb496cca67e13b&quot;
}
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongogridfs.storefile-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li class="member"> <span class="function"><a href="mongogridfs.put.html" class="function" rel="rdfs-seeAlso">MongoGridFS::put()</a> - Stores a file in the database</span></li>
   <li class="member"> <span class="function"><a href="mongogridfs.storebytes.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeBytes()</a> - Stores a string of bytes in the database</span></li>
   <li class="member"> <span class="function"><a href="mongogridfs.storeupload.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeUpload()</a> - Stores an uploaded file in the database</span></li>
   <li class="member">MongoDB core docs on <a href="http://docs.mongodb.org/manual/core/gridfs/" class="link external">&raquo;&nbsp;GridFS</a></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongogridfs.storebytes.html">MongoGridFS::storeBytes</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongogridfs.storeupload.html">MongoGridFS::storeUpload</a></div>
 <div class="up"><a href="class.mongogridfs.html">MongoGridFS</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>