<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.finfo-open" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>finfo_open</refname>
  <refname>finfo::__construct</refname>
  <refpurpose>Create a new finfo instance</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <para>&style.procedural;</para>
  <methodsynopsis>
   <type class="union"><type>finfo</type><type>false</type></type><methodname>finfo_open</methodname>
   <methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>FILEINFO_NONE</constant></initializer></methodparam>
   <methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>magic_database</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>&style.oop; (constructor):</para>
  <constructorsynopsis role="finfo">
   <modifier>public</modifier> <methodname>finfo::__construct</methodname>
   <methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>FILEINFO_NONE</constant></initializer></methodparam>
   <methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>magic_database</parameter><initializer>&null;</initializer></methodparam>
  </constructorsynopsis>
  <para>
   This function opens a magic database and returns its instance.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>flags</parameter></term>
     <listitem>
      <para>
       One or disjunction of more <link linkend="fileinfo.constants">Fileinfo
       constants</link>.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>magic_database</parameter></term>
     <listitem>
      <para>
       Name of a magic database file, usually something like
       <filename>/path/to/magic.mime</filename>. If not specified, the
       <literal>MAGIC</literal> environment variable is used. If the
       environment variable isn't set, then PHP's bundled magic database will
       be used.
      </para>
      <para>
       Passing &null; or an empty string will be equivalent to the default
       value.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   (Procedural style only)
   Returns an <classname>finfo</classname> instance on success,&return.falseforfailure;.
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>8.1.0</entry>
      <entry>
       Returns an <classname>finfo</classname> instance now;
       previously, a &resource; was returned.
      </entry>
     </row>
     <row>
      <entry>8.0.3</entry>
      <entry>
       <parameter>magic_database</parameter> is nullable now.
      </entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title>&style.oop;</title>
   <programlisting role="php">
<![CDATA[
<?php
$finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension

/* get mime-type for a specific file */
$filename = "/usr/local/something.txt";
echo $finfo->file($filename);

?>
]]>
  </programlisting>
  </example>
  <example>
   <title>&style.procedural;</title>
   <programlisting role="php">
<![CDATA[
<?php
$finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension

if (!$finfo) {
    echo "Opening fileinfo database failed";
    exit();
}

/* get mime-type for a specific file */
$filename = "/usr/local/something.txt";
echo finfo_file($finfo, $filename);

/* close connection */
finfo_close($finfo);
?>
]]>
   </programlisting>
  </example>
  &example.outputs;
  <screen>
<![CDATA[
text/plain; charset=us-ascii
]]>
  </screen>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    Generally, using the bundled magic database (by leaving
    <parameter>magic_database</parameter> and the <literal>MAGIC</literal>
    environment variables unset) is the best course of action unless you
    specifically need a custom magic database.
   </para>
  </note>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>finfo_close</function></member>
   </simplelist>
  </para>
 </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
indent-tabs-mode:nil
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
-->
