Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 9503

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 an uploaded 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.storefile.html">MongoGridFS::storeFile</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.mongogridfsfile.html">MongoGridFSFile</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.storeupload" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoGridFS::storeUpload</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.0)</p><p class="refpurpose"><span class="refname">MongoGridFS::storeUpload</span> &mdash; <span class="dc-title">Stores an uploaded file in the database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongogridfs.storeupload-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::storeUpload</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$metadata</code></span>
  ] )</div>

 </div>


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

    <dt>

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

      <p class="para">
       The name of the uploaded file to store. This should correspond to the
       file field&#039;s <em>name</em> attribute in the HTML form.
      </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>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        The <em>filename</em> index will be populated with the
        filename used.
       </p>
      </p></blockquote>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongogridfs.storeupload-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 changelog" id="refsect1-mongogridfs.storeupload-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.2.5</td>
       <td>
        Changed second parameter to an array of metadata. Pre-1.2.5, the
        second parameter was an optional string overriding the filename.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongogridfs.storeupload-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1508">
   <p><strong>Example #1  <span class="function"><strong>MongoGridFS::storeUpload()</strong></span> HTML form example</strong></p>
   <div class="example-contents"><p>
    Suppose you have the following HTML form:
   </p></div>
   <div class="example-contents">
<div class="htmlcode"><pre class="htmlcode">&lt;form method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;
    &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; /&gt;

    &lt;label for=&quot;pic&quot;&gt;Please upload a profile picture:&lt;/label&gt;
    &lt;input type=&quot;file&quot; name=&quot;pic&quot; id=&quot;pic&quot; /&gt;

    &lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;</pre>
</div>
   </div>

   <div class="example-contents"><p>
    If you wanted to store the uploaded image in MongoDB, you could do the
    following in the script handling the form submission:
   </p></div>
   <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">$gridfs</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">storeUpload</span><span style="color: #007700">(</span><span style="color: #DD0000">'pic'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'username'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongogridfs.storeupload-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.storefile.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeFile()</a> - Stores a 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.storefile.html">MongoGridFS::storeFile</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.mongogridfsfile.html">MongoGridFSFile</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>