<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.fileinfo.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.finfo-open.php',
    1 => 'finfo_open',
    2 => 'Create a new finfo instance',
  ),
  'up' => 
  array (
    0 => 'ref.fileinfo.php',
    1 => 'Fileinfo Functions',
  ),
  'prev' => 
  array (
    0 => 'function.finfo-file.php',
    1 => 'finfo_file',
  ),
  'next' => 
  array (
    0 => 'function.finfo-set-flags.php',
    1 => 'finfo_set_flags',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/fileinfo/functions/finfo-open.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.finfo-open" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">finfo_open</h1>
  <h1 class="refname">finfo::__construct</h1>
  <p class="verinfo">(PHP &gt;= 5.3.0, PHP 7, PHP 8, PECL fileinfo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">finfo_open</span> -- <span class="refname">finfo::__construct</span> &mdash; <span class="dc-title">Create a new finfo instance</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.finfo-open-description">
  <h3 class="title">Description</h3>
  <p class="simpara">Procedural style</p>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>finfo_open</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="fileinfo.constants.php#constant.fileinfo-none">FILEINFO_NONE</a></code></strong></span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$magic_database</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="class.finfo.php" class="type finfo">finfo</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">Object-oriented style (constructor):</p>
  <div class="constructorsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="finfo.construct.php" class="methodname">finfo::__construct</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="fileinfo.constants.php#constant.fileinfo-none">FILEINFO_NONE</a></code></strong></span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$magic_database</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>)</div>

  <p class="simpara">
   This function opens a magic database and returns its instance.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.finfo-open-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">flags</code></dt>
    <dd>
     <span class="simpara">
      One or disjunction of more <a href="fileinfo.constants.php" class="link">Fileinfo
      constants</a>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">magic_database</code></dt>
    <dd>
     <span class="simpara">
      Name of a magic database file, usually something like
      <var class="filename">/path/to/magic.mime</var>. If not specified, the
      <code class="literal">MAGIC</code> environment variable is used. If the
      environment variable isn&#039;t set, then PHP&#039;s bundled magic database will
      be used.
     </span>
     <span class="simpara">
      Passing <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> or an empty string will be equivalent to the default
      value.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.finfo-open-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   (Procedural style only)
   Returns an <span class="classname"><a href="class.finfo.php" class="classname">finfo</a></span> instance on success, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.finfo-open-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       Returns an <span class="classname"><a href="class.finfo.php" class="classname">finfo</a></span> instance now;
       previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was returned.
      </td>
     </tr>

     <tr>
      <td>8.0.3</td>
      <td>
       <code class="parameter">magic_database</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.finfo-open-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 Object-oriented style</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$finfo </span><span style="color: #007700">= new </span><span style="color: #0000BB">finfo</span><span style="color: #007700">(</span><span style="color: #0000BB">FILEINFO_MIME</span><span style="color: #007700">, </span><span style="color: #DD0000">"/usr/share/misc/magic"</span><span style="color: #007700">); </span><span style="color: #FF8000">// return mime type ala mimetype extension<br /><br />/* get mime-type for a specific file */<br /></span><span style="color: #0000BB">$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">"/usr/local/something.txt"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$finfo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 Procedural style</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$finfo </span><span style="color: #007700">= </span><span style="color: #0000BB">finfo_open</span><span style="color: #007700">(</span><span style="color: #0000BB">FILEINFO_MIME</span><span style="color: #007700">, </span><span style="color: #DD0000">"/usr/share/misc/magic"</span><span style="color: #007700">); </span><span style="color: #FF8000">// return mime type ala mimetype extension<br /><br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">$finfo</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Opening fileinfo database failed"</span><span style="color: #007700">;<br />    exit();<br />}<br /><br /></span><span style="color: #FF8000">/* get mime-type for a specific file */<br /></span><span style="color: #0000BB">$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">"/usr/local/something.txt"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">finfo_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$finfo</span><span style="color: #007700">, </span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* close connection */<br /></span><span style="color: #0000BB">finfo_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$finfo</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <p class="para">The above example will output:</p>
  <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">text/plain; charset=us-ascii</pre>
</div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.finfo-open-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Generally, using the bundled magic database (by leaving
    <code class="parameter">magic_database</code> and the <code class="literal">MAGIC</code>
    environment variables unset) is the best course of action unless you
    specifically need a custom magic database.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.finfo-open-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.finfo-close.php" class="function" rel="rdfs-seeAlso">finfo_close()</a> - Close finfo instance</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>